Colouring aligned math text with macros
I would like to have coloured text-generating macros that i can use inside an align* environment. However, the two seem conflicting.
Here's a MWE describing the issue.
documentclass{article}
usepackage{amsmath}
usepackage[usenames,dvipsnames]{xcolor}
newcommand{src}[1]{ensuremath{color{RoyalBlue}{#1}}}
newcommand{letin}[3]{let~#1=#2~in~#3}
newcommand{letinsrc}[3]{src{let}~#1=#2~src{in}~#3}
begin{document}
This is on a single line and it works
begin{align*}
src{letin{x}{3}{x}}
end{align*}
Here i want to break the text over multiple lines and it does not work
% begin{align*}
% &
% src{
% letin{x}{3}{
% \&
% x}
% }
% end{align*}
This is how it should look like, but the issue is the extra usage of ``src'' inside the macro.
begin{align*}
&
letinsrc{x}{src{3}}{
\
&
src{x}
}
end{align*}
end{document}
Intuitively, i would just like a macro for setting the colour, no matter where, and a macro for the letin construct.
The problem is that the workaround is not modular, it is ... well, a workaround and not a solution.
If i have more colours, i must define multiple versions of letinsrc and i must wrap each of the arguments in their own src.
That leads to tons of nested src while i would just like a single src at the beginning of the align*.
Also, in the letinsrc command, i cannot wrap the arguments in src, as there will be the line breaks and alignments ampersands and that won't compile.
Thanks!
color align amsmath
add a comment |
I would like to have coloured text-generating macros that i can use inside an align* environment. However, the two seem conflicting.
Here's a MWE describing the issue.
documentclass{article}
usepackage{amsmath}
usepackage[usenames,dvipsnames]{xcolor}
newcommand{src}[1]{ensuremath{color{RoyalBlue}{#1}}}
newcommand{letin}[3]{let~#1=#2~in~#3}
newcommand{letinsrc}[3]{src{let}~#1=#2~src{in}~#3}
begin{document}
This is on a single line and it works
begin{align*}
src{letin{x}{3}{x}}
end{align*}
Here i want to break the text over multiple lines and it does not work
% begin{align*}
% &
% src{
% letin{x}{3}{
% \&
% x}
% }
% end{align*}
This is how it should look like, but the issue is the extra usage of ``src'' inside the macro.
begin{align*}
&
letinsrc{x}{src{3}}{
\
&
src{x}
}
end{align*}
end{document}
Intuitively, i would just like a macro for setting the colour, no matter where, and a macro for the letin construct.
The problem is that the workaround is not modular, it is ... well, a workaround and not a solution.
If i have more colours, i must define multiple versions of letinsrc and i must wrap each of the arguments in their own src.
That leads to tons of nested src while i would just like a single src at the beginning of the align*.
Also, in the letinsrc command, i cannot wrap the arguments in src, as there will be the line breaks and alignments ampersands and that won't compile.
Thanks!
color align amsmath
1
You cannot have a group{...}spread across&withinalign(orarray, ortabular, or ...). That's what you're trying to do with your macrosrcin the second instance where it doesn't work:src{ ... & ... }. You'll have to break this up into segments likesrc{ ... } & src{ ... }or use another method of alignment.
– Werner
2 hours ago
@Werner ouch. But perhaps there is some other way, e.g., saying "change text to red from now on" before the align (or better, within the align), and then "change text to black from now on" when one is done with it?
– Squera
1 hour ago
2
Withinaligneach "cell" (between&) forms a group with limited scope. That's just the way it is. Yes, you can place the colour change outsidealign, but that would affect the entirealign.
– Werner
1 hour ago
add a comment |
I would like to have coloured text-generating macros that i can use inside an align* environment. However, the two seem conflicting.
Here's a MWE describing the issue.
documentclass{article}
usepackage{amsmath}
usepackage[usenames,dvipsnames]{xcolor}
newcommand{src}[1]{ensuremath{color{RoyalBlue}{#1}}}
newcommand{letin}[3]{let~#1=#2~in~#3}
newcommand{letinsrc}[3]{src{let}~#1=#2~src{in}~#3}
begin{document}
This is on a single line and it works
begin{align*}
src{letin{x}{3}{x}}
end{align*}
Here i want to break the text over multiple lines and it does not work
% begin{align*}
% &
% src{
% letin{x}{3}{
% \&
% x}
% }
% end{align*}
This is how it should look like, but the issue is the extra usage of ``src'' inside the macro.
begin{align*}
&
letinsrc{x}{src{3}}{
\
&
src{x}
}
end{align*}
end{document}
Intuitively, i would just like a macro for setting the colour, no matter where, and a macro for the letin construct.
The problem is that the workaround is not modular, it is ... well, a workaround and not a solution.
If i have more colours, i must define multiple versions of letinsrc and i must wrap each of the arguments in their own src.
That leads to tons of nested src while i would just like a single src at the beginning of the align*.
Also, in the letinsrc command, i cannot wrap the arguments in src, as there will be the line breaks and alignments ampersands and that won't compile.
Thanks!
color align amsmath
I would like to have coloured text-generating macros that i can use inside an align* environment. However, the two seem conflicting.
Here's a MWE describing the issue.
documentclass{article}
usepackage{amsmath}
usepackage[usenames,dvipsnames]{xcolor}
newcommand{src}[1]{ensuremath{color{RoyalBlue}{#1}}}
newcommand{letin}[3]{let~#1=#2~in~#3}
newcommand{letinsrc}[3]{src{let}~#1=#2~src{in}~#3}
begin{document}
This is on a single line and it works
begin{align*}
src{letin{x}{3}{x}}
end{align*}
Here i want to break the text over multiple lines and it does not work
% begin{align*}
% &
% src{
% letin{x}{3}{
% \&
% x}
% }
% end{align*}
This is how it should look like, but the issue is the extra usage of ``src'' inside the macro.
begin{align*}
&
letinsrc{x}{src{3}}{
\
&
src{x}
}
end{align*}
end{document}
Intuitively, i would just like a macro for setting the colour, no matter where, and a macro for the letin construct.
The problem is that the workaround is not modular, it is ... well, a workaround and not a solution.
If i have more colours, i must define multiple versions of letinsrc and i must wrap each of the arguments in their own src.
That leads to tons of nested src while i would just like a single src at the beginning of the align*.
Also, in the letinsrc command, i cannot wrap the arguments in src, as there will be the line breaks and alignments ampersands and that won't compile.
Thanks!
color align amsmath
color align amsmath
asked 2 hours ago
Squera
1787
1787
1
You cannot have a group{...}spread across&withinalign(orarray, ortabular, or ...). That's what you're trying to do with your macrosrcin the second instance where it doesn't work:src{ ... & ... }. You'll have to break this up into segments likesrc{ ... } & src{ ... }or use another method of alignment.
– Werner
2 hours ago
@Werner ouch. But perhaps there is some other way, e.g., saying "change text to red from now on" before the align (or better, within the align), and then "change text to black from now on" when one is done with it?
– Squera
1 hour ago
2
Withinaligneach "cell" (between&) forms a group with limited scope. That's just the way it is. Yes, you can place the colour change outsidealign, but that would affect the entirealign.
– Werner
1 hour ago
add a comment |
1
You cannot have a group{...}spread across&withinalign(orarray, ortabular, or ...). That's what you're trying to do with your macrosrcin the second instance where it doesn't work:src{ ... & ... }. You'll have to break this up into segments likesrc{ ... } & src{ ... }or use another method of alignment.
– Werner
2 hours ago
@Werner ouch. But perhaps there is some other way, e.g., saying "change text to red from now on" before the align (or better, within the align), and then "change text to black from now on" when one is done with it?
– Squera
1 hour ago
2
Withinaligneach "cell" (between&) forms a group with limited scope. That's just the way it is. Yes, you can place the colour change outsidealign, but that would affect the entirealign.
– Werner
1 hour ago
1
1
You cannot have a group
{...} spread across & within align (or array, or tabular, or ...). That's what you're trying to do with your macro src in the second instance where it doesn't work: src{ ... & ... }. You'll have to break this up into segments like src{ ... } & src{ ... } or use another method of alignment.– Werner
2 hours ago
You cannot have a group
{...} spread across & within align (or array, or tabular, or ...). That's what you're trying to do with your macro src in the second instance where it doesn't work: src{ ... & ... }. You'll have to break this up into segments like src{ ... } & src{ ... } or use another method of alignment.– Werner
2 hours ago
@Werner ouch. But perhaps there is some other way, e.g., saying "change text to red from now on" before the align (or better, within the align), and then "change text to black from now on" when one is done with it?
– Squera
1 hour ago
@Werner ouch. But perhaps there is some other way, e.g., saying "change text to red from now on" before the align (or better, within the align), and then "change text to black from now on" when one is done with it?
– Squera
1 hour ago
2
2
Within
align each "cell" (between &) forms a group with limited scope. That's just the way it is. Yes, you can place the colour change outside align, but that would affect the entire align.– Werner
1 hour ago
Within
align each "cell" (between &) forms a group with limited scope. That's just the way it is. Yes, you can place the colour change outside align, but that would affect the entire align.– Werner
1 hour ago
add a comment |
0
active
oldest
votes
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',
autoActivateHeartbeat: false,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468348%2fcolouring-aligned-math-text-with-macros%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468348%2fcolouring-aligned-math-text-with-macros%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
You cannot have a group
{...}spread across&withinalign(orarray, ortabular, or ...). That's what you're trying to do with your macrosrcin the second instance where it doesn't work:src{ ... & ... }. You'll have to break this up into segments likesrc{ ... } & src{ ... }or use another method of alignment.– Werner
2 hours ago
@Werner ouch. But perhaps there is some other way, e.g., saying "change text to red from now on" before the align (or better, within the align), and then "change text to black from now on" when one is done with it?
– Squera
1 hour ago
2
Within
aligneach "cell" (between&) forms a group with limited scope. That's just the way it is. Yes, you can place the colour change outsidealign, but that would affect the entirealign.– Werner
1 hour ago