Defining colors in style file by forcing immediate expansion











up vote
0
down vote

favorite












I am writing a template for a poster (using beamer/beamerposter) package for students that I intend to distribute as a folder. It will contain a .tex file that the students can start editing, and a style file, which is a custom beamer theme, that I do not want them to mess with.



The theme is already designed to look nice with one user-specified color, with all other structure and text colors derived from that color using colorlet{usercolor!10!white} etc. type of mixins.



The thing works as defined above.



The work is nearly done, except for one vexing issue. I want the students to be able to define the user-specified color in the .tex file and not have to ever edit the style file.



So, I tried the following:



beamerthemeXXX.sty:



...
newcommand{postercolor}[3]{def@posterR{#1}def@posterG{#2}def@posterB{#3}}
definecolor{posterthemecolor}{RGB}{@posterR,@posterG,@posterB}
...


I have the following directive in .tex file:



postercolor{128}{0}{0}


I get a lot undefined control sequence errors in the style file where I am using @posterX macros.



I guess that this question is more TeX and less color related. How do I force the def's in the newcommand definition above to expand immediately?



I apologize for not providing an MWE as there are several files involved, some containing confidential information. In any case, I have a hunch that this problem is largely due to my programming brain failing to come to terms with some TeX peculiarities.










share|improve this question






















  • Why not just directly define the colour inside postercolor? (newcommand{postercolor}[3]{definecolor{posterthemecolor}{RGB}{#1,#2,#3}}) Or for that matter, is it that hard for your students to just use definecolor{posterthemecolor} directly in their tex file?
    – David Purton
    Nov 17 at 10:02










  • Thanks @DavidPurton. However, that does not solve the problem. I get the same error as before, because as I suspect, the newcommand macro inside the style file is not actually expanded when postercolor{128}{0}{0} is called from outside. I need something forces the evaluation of the command when it is called inside the theme. As to the other suggestion, that is a) supposes that the students won't mess up the definition, b) does not modularly separate out the elements of the poster (that I expect them to worry about), and elements of TeX (that I do not expect them to worry about).
    – user2751530
    Nov 17 at 16:29












  • In that case we do need a MWE. Condense it to one file (just put relevant things in the preamble). Leave out all your confidential stuff since it is not relevant to the problem. As you have it at the moment in your question the most likely reason for undefined references is because you call definecolor in the sty file before postercolor is called in the tex file. My suggestion does work, so something else is going wrong in your file that I can't guess.
    – David Purton
    Nov 17 at 21:50

















up vote
0
down vote

favorite












I am writing a template for a poster (using beamer/beamerposter) package for students that I intend to distribute as a folder. It will contain a .tex file that the students can start editing, and a style file, which is a custom beamer theme, that I do not want them to mess with.



The theme is already designed to look nice with one user-specified color, with all other structure and text colors derived from that color using colorlet{usercolor!10!white} etc. type of mixins.



The thing works as defined above.



The work is nearly done, except for one vexing issue. I want the students to be able to define the user-specified color in the .tex file and not have to ever edit the style file.



So, I tried the following:



beamerthemeXXX.sty:



...
newcommand{postercolor}[3]{def@posterR{#1}def@posterG{#2}def@posterB{#3}}
definecolor{posterthemecolor}{RGB}{@posterR,@posterG,@posterB}
...


I have the following directive in .tex file:



postercolor{128}{0}{0}


I get a lot undefined control sequence errors in the style file where I am using @posterX macros.



I guess that this question is more TeX and less color related. How do I force the def's in the newcommand definition above to expand immediately?



I apologize for not providing an MWE as there are several files involved, some containing confidential information. In any case, I have a hunch that this problem is largely due to my programming brain failing to come to terms with some TeX peculiarities.










share|improve this question






















  • Why not just directly define the colour inside postercolor? (newcommand{postercolor}[3]{definecolor{posterthemecolor}{RGB}{#1,#2,#3}}) Or for that matter, is it that hard for your students to just use definecolor{posterthemecolor} directly in their tex file?
    – David Purton
    Nov 17 at 10:02










  • Thanks @DavidPurton. However, that does not solve the problem. I get the same error as before, because as I suspect, the newcommand macro inside the style file is not actually expanded when postercolor{128}{0}{0} is called from outside. I need something forces the evaluation of the command when it is called inside the theme. As to the other suggestion, that is a) supposes that the students won't mess up the definition, b) does not modularly separate out the elements of the poster (that I expect them to worry about), and elements of TeX (that I do not expect them to worry about).
    – user2751530
    Nov 17 at 16:29












  • In that case we do need a MWE. Condense it to one file (just put relevant things in the preamble). Leave out all your confidential stuff since it is not relevant to the problem. As you have it at the moment in your question the most likely reason for undefined references is because you call definecolor in the sty file before postercolor is called in the tex file. My suggestion does work, so something else is going wrong in your file that I can't guess.
    – David Purton
    Nov 17 at 21:50















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am writing a template for a poster (using beamer/beamerposter) package for students that I intend to distribute as a folder. It will contain a .tex file that the students can start editing, and a style file, which is a custom beamer theme, that I do not want them to mess with.



The theme is already designed to look nice with one user-specified color, with all other structure and text colors derived from that color using colorlet{usercolor!10!white} etc. type of mixins.



The thing works as defined above.



The work is nearly done, except for one vexing issue. I want the students to be able to define the user-specified color in the .tex file and not have to ever edit the style file.



So, I tried the following:



beamerthemeXXX.sty:



...
newcommand{postercolor}[3]{def@posterR{#1}def@posterG{#2}def@posterB{#3}}
definecolor{posterthemecolor}{RGB}{@posterR,@posterG,@posterB}
...


I have the following directive in .tex file:



postercolor{128}{0}{0}


I get a lot undefined control sequence errors in the style file where I am using @posterX macros.



I guess that this question is more TeX and less color related. How do I force the def's in the newcommand definition above to expand immediately?



I apologize for not providing an MWE as there are several files involved, some containing confidential information. In any case, I have a hunch that this problem is largely due to my programming brain failing to come to terms with some TeX peculiarities.










share|improve this question













I am writing a template for a poster (using beamer/beamerposter) package for students that I intend to distribute as a folder. It will contain a .tex file that the students can start editing, and a style file, which is a custom beamer theme, that I do not want them to mess with.



The theme is already designed to look nice with one user-specified color, with all other structure and text colors derived from that color using colorlet{usercolor!10!white} etc. type of mixins.



The thing works as defined above.



The work is nearly done, except for one vexing issue. I want the students to be able to define the user-specified color in the .tex file and not have to ever edit the style file.



So, I tried the following:



beamerthemeXXX.sty:



...
newcommand{postercolor}[3]{def@posterR{#1}def@posterG{#2}def@posterB{#3}}
definecolor{posterthemecolor}{RGB}{@posterR,@posterG,@posterB}
...


I have the following directive in .tex file:



postercolor{128}{0}{0}


I get a lot undefined control sequence errors in the style file where I am using @posterX macros.



I guess that this question is more TeX and less color related. How do I force the def's in the newcommand definition above to expand immediately?



I apologize for not providing an MWE as there are several files involved, some containing confidential information. In any case, I have a hunch that this problem is largely due to my programming brain failing to come to terms with some TeX peculiarities.







color tex-core package-writing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 17 at 9:22









user2751530

524315




524315












  • Why not just directly define the colour inside postercolor? (newcommand{postercolor}[3]{definecolor{posterthemecolor}{RGB}{#1,#2,#3}}) Or for that matter, is it that hard for your students to just use definecolor{posterthemecolor} directly in their tex file?
    – David Purton
    Nov 17 at 10:02










  • Thanks @DavidPurton. However, that does not solve the problem. I get the same error as before, because as I suspect, the newcommand macro inside the style file is not actually expanded when postercolor{128}{0}{0} is called from outside. I need something forces the evaluation of the command when it is called inside the theme. As to the other suggestion, that is a) supposes that the students won't mess up the definition, b) does not modularly separate out the elements of the poster (that I expect them to worry about), and elements of TeX (that I do not expect them to worry about).
    – user2751530
    Nov 17 at 16:29












  • In that case we do need a MWE. Condense it to one file (just put relevant things in the preamble). Leave out all your confidential stuff since it is not relevant to the problem. As you have it at the moment in your question the most likely reason for undefined references is because you call definecolor in the sty file before postercolor is called in the tex file. My suggestion does work, so something else is going wrong in your file that I can't guess.
    – David Purton
    Nov 17 at 21:50




















  • Why not just directly define the colour inside postercolor? (newcommand{postercolor}[3]{definecolor{posterthemecolor}{RGB}{#1,#2,#3}}) Or for that matter, is it that hard for your students to just use definecolor{posterthemecolor} directly in their tex file?
    – David Purton
    Nov 17 at 10:02










  • Thanks @DavidPurton. However, that does not solve the problem. I get the same error as before, because as I suspect, the newcommand macro inside the style file is not actually expanded when postercolor{128}{0}{0} is called from outside. I need something forces the evaluation of the command when it is called inside the theme. As to the other suggestion, that is a) supposes that the students won't mess up the definition, b) does not modularly separate out the elements of the poster (that I expect them to worry about), and elements of TeX (that I do not expect them to worry about).
    – user2751530
    Nov 17 at 16:29












  • In that case we do need a MWE. Condense it to one file (just put relevant things in the preamble). Leave out all your confidential stuff since it is not relevant to the problem. As you have it at the moment in your question the most likely reason for undefined references is because you call definecolor in the sty file before postercolor is called in the tex file. My suggestion does work, so something else is going wrong in your file that I can't guess.
    – David Purton
    Nov 17 at 21:50


















Why not just directly define the colour inside postercolor? (newcommand{postercolor}[3]{definecolor{posterthemecolor}{RGB}{#1,#2,#3}}) Or for that matter, is it that hard for your students to just use definecolor{posterthemecolor} directly in their tex file?
– David Purton
Nov 17 at 10:02




Why not just directly define the colour inside postercolor? (newcommand{postercolor}[3]{definecolor{posterthemecolor}{RGB}{#1,#2,#3}}) Or for that matter, is it that hard for your students to just use definecolor{posterthemecolor} directly in their tex file?
– David Purton
Nov 17 at 10:02












Thanks @DavidPurton. However, that does not solve the problem. I get the same error as before, because as I suspect, the newcommand macro inside the style file is not actually expanded when postercolor{128}{0}{0} is called from outside. I need something forces the evaluation of the command when it is called inside the theme. As to the other suggestion, that is a) supposes that the students won't mess up the definition, b) does not modularly separate out the elements of the poster (that I expect them to worry about), and elements of TeX (that I do not expect them to worry about).
– user2751530
Nov 17 at 16:29






Thanks @DavidPurton. However, that does not solve the problem. I get the same error as before, because as I suspect, the newcommand macro inside the style file is not actually expanded when postercolor{128}{0}{0} is called from outside. I need something forces the evaluation of the command when it is called inside the theme. As to the other suggestion, that is a) supposes that the students won't mess up the definition, b) does not modularly separate out the elements of the poster (that I expect them to worry about), and elements of TeX (that I do not expect them to worry about).
– user2751530
Nov 17 at 16:29














In that case we do need a MWE. Condense it to one file (just put relevant things in the preamble). Leave out all your confidential stuff since it is not relevant to the problem. As you have it at the moment in your question the most likely reason for undefined references is because you call definecolor in the sty file before postercolor is called in the tex file. My suggestion does work, so something else is going wrong in your file that I can't guess.
– David Purton
Nov 17 at 21:50






In that case we do need a MWE. Condense it to one file (just put relevant things in the preamble). Leave out all your confidential stuff since it is not relevant to the problem. As you have it at the moment in your question the most likely reason for undefined references is because you call definecolor in the sty file before postercolor is called in the tex file. My suggestion does work, so something else is going wrong in your file that I can't guess.
– David Purton
Nov 17 at 21:50












1 Answer
1






active

oldest

votes

















up vote
1
down vote













You don't have to use the def@poster* macros at all. Just define the colour inside postercolor and ensure that it's initialised by your style.



documentclass{article}

%usepackage{beamerthemeXXX}

% contents of beamerthemeXXX.sty
usepackage{xcolor}
% ...
% define theme colour setting macro
newcommand{postercolor}[3]{definecolor{posterthemecolor}{RGB}{#1,#2,#3}}

% initialise theme colour
postercolor{128}{0}{0}
% ...
% end of beamerthemeXXX.sty

% user document preamble

% redefine theme colour if necessary
postercolor{0}{128}{0}

begin{document}

textcolor{posterthemecolor}{poster colour}

end{document}





share|improve this answer





















  • Thanks@DavidPurton. Correct me if I am wrong (based on commented out usepackage in your listing above), but does this not imply simply dumping the contents of the beamertheme.sty file into the main .tex file as a preamble? This would not be a practical possibility because my .sty file has about 500 lines, which I definitely do not want the students to be even accidentally messing up. The .tex file has about ~150 lines. I will try to get you a multi-file MWE as soon as I have time, but this is a package writing problem that cannot be avoided by just making one giant .tex file.
    – user2751530
    Nov 18 at 9:40












  • @user2751530 no, you put it in the style file and uncomment the usepackage line. I’m just showing the two lines you need in the style file and an example that will compile to produce the expected output.
    – David Purton
    Nov 18 at 10:32











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460420%2fdefining-colors-in-style-file-by-forcing-immediate-expansion%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













You don't have to use the def@poster* macros at all. Just define the colour inside postercolor and ensure that it's initialised by your style.



documentclass{article}

%usepackage{beamerthemeXXX}

% contents of beamerthemeXXX.sty
usepackage{xcolor}
% ...
% define theme colour setting macro
newcommand{postercolor}[3]{definecolor{posterthemecolor}{RGB}{#1,#2,#3}}

% initialise theme colour
postercolor{128}{0}{0}
% ...
% end of beamerthemeXXX.sty

% user document preamble

% redefine theme colour if necessary
postercolor{0}{128}{0}

begin{document}

textcolor{posterthemecolor}{poster colour}

end{document}





share|improve this answer





















  • Thanks@DavidPurton. Correct me if I am wrong (based on commented out usepackage in your listing above), but does this not imply simply dumping the contents of the beamertheme.sty file into the main .tex file as a preamble? This would not be a practical possibility because my .sty file has about 500 lines, which I definitely do not want the students to be even accidentally messing up. The .tex file has about ~150 lines. I will try to get you a multi-file MWE as soon as I have time, but this is a package writing problem that cannot be avoided by just making one giant .tex file.
    – user2751530
    Nov 18 at 9:40












  • @user2751530 no, you put it in the style file and uncomment the usepackage line. I’m just showing the two lines you need in the style file and an example that will compile to produce the expected output.
    – David Purton
    Nov 18 at 10:32















up vote
1
down vote













You don't have to use the def@poster* macros at all. Just define the colour inside postercolor and ensure that it's initialised by your style.



documentclass{article}

%usepackage{beamerthemeXXX}

% contents of beamerthemeXXX.sty
usepackage{xcolor}
% ...
% define theme colour setting macro
newcommand{postercolor}[3]{definecolor{posterthemecolor}{RGB}{#1,#2,#3}}

% initialise theme colour
postercolor{128}{0}{0}
% ...
% end of beamerthemeXXX.sty

% user document preamble

% redefine theme colour if necessary
postercolor{0}{128}{0}

begin{document}

textcolor{posterthemecolor}{poster colour}

end{document}





share|improve this answer





















  • Thanks@DavidPurton. Correct me if I am wrong (based on commented out usepackage in your listing above), but does this not imply simply dumping the contents of the beamertheme.sty file into the main .tex file as a preamble? This would not be a practical possibility because my .sty file has about 500 lines, which I definitely do not want the students to be even accidentally messing up. The .tex file has about ~150 lines. I will try to get you a multi-file MWE as soon as I have time, but this is a package writing problem that cannot be avoided by just making one giant .tex file.
    – user2751530
    Nov 18 at 9:40












  • @user2751530 no, you put it in the style file and uncomment the usepackage line. I’m just showing the two lines you need in the style file and an example that will compile to produce the expected output.
    – David Purton
    Nov 18 at 10:32













up vote
1
down vote










up vote
1
down vote









You don't have to use the def@poster* macros at all. Just define the colour inside postercolor and ensure that it's initialised by your style.



documentclass{article}

%usepackage{beamerthemeXXX}

% contents of beamerthemeXXX.sty
usepackage{xcolor}
% ...
% define theme colour setting macro
newcommand{postercolor}[3]{definecolor{posterthemecolor}{RGB}{#1,#2,#3}}

% initialise theme colour
postercolor{128}{0}{0}
% ...
% end of beamerthemeXXX.sty

% user document preamble

% redefine theme colour if necessary
postercolor{0}{128}{0}

begin{document}

textcolor{posterthemecolor}{poster colour}

end{document}





share|improve this answer












You don't have to use the def@poster* macros at all. Just define the colour inside postercolor and ensure that it's initialised by your style.



documentclass{article}

%usepackage{beamerthemeXXX}

% contents of beamerthemeXXX.sty
usepackage{xcolor}
% ...
% define theme colour setting macro
newcommand{postercolor}[3]{definecolor{posterthemecolor}{RGB}{#1,#2,#3}}

% initialise theme colour
postercolor{128}{0}{0}
% ...
% end of beamerthemeXXX.sty

% user document preamble

% redefine theme colour if necessary
postercolor{0}{128}{0}

begin{document}

textcolor{posterthemecolor}{poster colour}

end{document}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 18 at 5:05









David Purton

8,2841834




8,2841834












  • Thanks@DavidPurton. Correct me if I am wrong (based on commented out usepackage in your listing above), but does this not imply simply dumping the contents of the beamertheme.sty file into the main .tex file as a preamble? This would not be a practical possibility because my .sty file has about 500 lines, which I definitely do not want the students to be even accidentally messing up. The .tex file has about ~150 lines. I will try to get you a multi-file MWE as soon as I have time, but this is a package writing problem that cannot be avoided by just making one giant .tex file.
    – user2751530
    Nov 18 at 9:40












  • @user2751530 no, you put it in the style file and uncomment the usepackage line. I’m just showing the two lines you need in the style file and an example that will compile to produce the expected output.
    – David Purton
    Nov 18 at 10:32


















  • Thanks@DavidPurton. Correct me if I am wrong (based on commented out usepackage in your listing above), but does this not imply simply dumping the contents of the beamertheme.sty file into the main .tex file as a preamble? This would not be a practical possibility because my .sty file has about 500 lines, which I definitely do not want the students to be even accidentally messing up. The .tex file has about ~150 lines. I will try to get you a multi-file MWE as soon as I have time, but this is a package writing problem that cannot be avoided by just making one giant .tex file.
    – user2751530
    Nov 18 at 9:40












  • @user2751530 no, you put it in the style file and uncomment the usepackage line. I’m just showing the two lines you need in the style file and an example that will compile to produce the expected output.
    – David Purton
    Nov 18 at 10:32
















Thanks@DavidPurton. Correct me if I am wrong (based on commented out usepackage in your listing above), but does this not imply simply dumping the contents of the beamertheme.sty file into the main .tex file as a preamble? This would not be a practical possibility because my .sty file has about 500 lines, which I definitely do not want the students to be even accidentally messing up. The .tex file has about ~150 lines. I will try to get you a multi-file MWE as soon as I have time, but this is a package writing problem that cannot be avoided by just making one giant .tex file.
– user2751530
Nov 18 at 9:40






Thanks@DavidPurton. Correct me if I am wrong (based on commented out usepackage in your listing above), but does this not imply simply dumping the contents of the beamertheme.sty file into the main .tex file as a preamble? This would not be a practical possibility because my .sty file has about 500 lines, which I definitely do not want the students to be even accidentally messing up. The .tex file has about ~150 lines. I will try to get you a multi-file MWE as soon as I have time, but this is a package writing problem that cannot be avoided by just making one giant .tex file.
– user2751530
Nov 18 at 9:40














@user2751530 no, you put it in the style file and uncomment the usepackage line. I’m just showing the two lines you need in the style file and an example that will compile to produce the expected output.
– David Purton
Nov 18 at 10:32




@user2751530 no, you put it in the style file and uncomment the usepackage line. I’m just showing the two lines you need in the style file and an example that will compile to produce the expected output.
– David Purton
Nov 18 at 10:32


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460420%2fdefining-colors-in-style-file-by-forcing-immediate-expansion%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?