Coloring maths inside a tcolorboxWhy is [ … ] preferable to $$ … $$?Why choose LuaLaTeX over XeLaTeX?Maintaining text colour change in a breakable tcolorboxAdding an Image inside tcolorboxUse algorithm2e inside tcolorboxmath inside title in tcolorboxItemize inside TcolorboxClip background image inside tcolorboxsetting text size inside tcolorboxMulticolumns inside tcolorbox breakable boxParagraph breaks inside tcolorboxtodo notes inside tcolorbox
What is expected in a 5 minute postdoc interview presentation?
Tuning fork in last two episodes of Legion S02
Found a minor bug, affecting 1% of users. What should QA do?
How is погода (weather) a count noun?
Unable to delete GeoTIFF after adding it to GeoServer
Is it possible for both sides of an encounter to be surprised?
What would the EU’s position be with respect to a United Ireland?
Could Boris Johnson face criminal charges for illegally proroguing Parliament?
What is the difference between increasing volume and increasing gain?
Booting Ubuntu from USB drive on MSI motherboard -- EVERYTHING fails
Lighthouse Alternatives
As a girl, how can I voice male characters effectively?
C Clef Showing Middle C on the Second Space: Printing Error, or Obscure Clef?
Anonymous reviewer disclosed his identity. Should I thank him by name?
Can/should you swim in zero G?
How is this situation not a checkmate?
Tikz background color of node multilayer
Job interview by video at home and privacy concerns
Present participles of the verb esse
Why is there such a singular place for bird watching?
Realistically, how much do you need to start investing?
Bothered by watching coworkers slacking off
How Concerning Is This X-CU-modified: FAKECU Text Attack?
Sci-fi story about aliens with cells based on arsenic or nitrogen, poisoned by oxygen
Coloring maths inside a tcolorbox
Why is [ … ] preferable to $$ … $$?Why choose LuaLaTeX over XeLaTeX?Maintaining text colour change in a breakable tcolorboxAdding an Image inside tcolorboxUse algorithm2e inside tcolorboxmath inside title in tcolorboxItemize inside TcolorboxClip background image inside tcolorboxsetting text size inside tcolorboxMulticolumns inside tcolorbox breakable boxParagraph breaks inside tcolorboxtodo notes inside tcolorbox
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
My TeX level isn't the greatest, I am trying hard to improve but I am always struggling.
I would like to change the color of text inside a tcolorbox and that this color formatting survives a pagebreak. This doesn't seem to be possible according to what I found here : Maintaining text colour change in a breakable tcolorbox
but it seems to be possible under XeTeX using fontspec. I have one last problem before I finally manage to solve this problem I have add for more than a year and many hours of swearing, this doesn't seem to apply to text put in math mode.
Here is a MWE based on what the link above :
documentclassarticle
usepackagemathspec
setmainfontPalatino
usepackageblindtext
usepackage[breakable]tcolorbox
begindocument
begintcolorbox[breakable]
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtext
$$F=ma$$
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtext
endtcolorbox
enddocument
Is it possible to get the $$F=ma$$ in brown ?
Of course, any solution using the xcolor package won't work because of the incompatibility with tcolorbox, so I really need a font-associated solution. I had a look at the mathspec package but couldn't find the solution in the documentation. I somehow feel it shouldn't be that hard though.
Thanks in advance !
fontspec tcolorbox
add a comment
|
My TeX level isn't the greatest, I am trying hard to improve but I am always struggling.
I would like to change the color of text inside a tcolorbox and that this color formatting survives a pagebreak. This doesn't seem to be possible according to what I found here : Maintaining text colour change in a breakable tcolorbox
but it seems to be possible under XeTeX using fontspec. I have one last problem before I finally manage to solve this problem I have add for more than a year and many hours of swearing, this doesn't seem to apply to text put in math mode.
Here is a MWE based on what the link above :
documentclassarticle
usepackagemathspec
setmainfontPalatino
usepackageblindtext
usepackage[breakable]tcolorbox
begindocument
begintcolorbox[breakable]
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtext
$$F=ma$$
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtext
endtcolorbox
enddocument
Is it possible to get the $$F=ma$$ in brown ?
Of course, any solution using the xcolor package won't work because of the incompatibility with tcolorbox, so I really need a font-associated solution. I had a look at the mathspec package but couldn't find the solution in the documentation. I somehow feel it shouldn't be that hard though.
Thanks in advance !
fontspec tcolorbox
1
Don't use$$...$$- that's deprecated
– ufo
Apr 16 at 12:00
2
how cantcolorboxbe incompatible withxcolor? It is automatically loaded when you suetcolorbox. There is no way to usetcolorboxwithoutxcolor
– ufo
Apr 16 at 12:03
@ufo the problem is not with xcolor per se but with color at pagebreaks.
– Ulrike Fischer
Apr 16 at 12:22
The local formatting breaks if the page breaks. It happens to me quite often that the local formatting by using something likeextras=colupper=redis lost once the pages breaks.
– HerculePoivrot
Apr 16 at 12:23
add a comment
|
My TeX level isn't the greatest, I am trying hard to improve but I am always struggling.
I would like to change the color of text inside a tcolorbox and that this color formatting survives a pagebreak. This doesn't seem to be possible according to what I found here : Maintaining text colour change in a breakable tcolorbox
but it seems to be possible under XeTeX using fontspec. I have one last problem before I finally manage to solve this problem I have add for more than a year and many hours of swearing, this doesn't seem to apply to text put in math mode.
Here is a MWE based on what the link above :
documentclassarticle
usepackagemathspec
setmainfontPalatino
usepackageblindtext
usepackage[breakable]tcolorbox
begindocument
begintcolorbox[breakable]
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtext
$$F=ma$$
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtext
endtcolorbox
enddocument
Is it possible to get the $$F=ma$$ in brown ?
Of course, any solution using the xcolor package won't work because of the incompatibility with tcolorbox, so I really need a font-associated solution. I had a look at the mathspec package but couldn't find the solution in the documentation. I somehow feel it shouldn't be that hard though.
Thanks in advance !
fontspec tcolorbox
My TeX level isn't the greatest, I am trying hard to improve but I am always struggling.
I would like to change the color of text inside a tcolorbox and that this color formatting survives a pagebreak. This doesn't seem to be possible according to what I found here : Maintaining text colour change in a breakable tcolorbox
but it seems to be possible under XeTeX using fontspec. I have one last problem before I finally manage to solve this problem I have add for more than a year and many hours of swearing, this doesn't seem to apply to text put in math mode.
Here is a MWE based on what the link above :
documentclassarticle
usepackagemathspec
setmainfontPalatino
usepackageblindtext
usepackage[breakable]tcolorbox
begindocument
begintcolorbox[breakable]
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtext
$$F=ma$$
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtext
endtcolorbox
enddocument
Is it possible to get the $$F=ma$$ in brown ?
Of course, any solution using the xcolor package won't work because of the incompatibility with tcolorbox, so I really need a font-associated solution. I had a look at the mathspec package but couldn't find the solution in the documentation. I somehow feel it shouldn't be that hard though.
Thanks in advance !
fontspec tcolorbox
fontspec tcolorbox
asked Apr 16 at 11:28
HerculePoivrotHerculePoivrot
5110 bronze badges
5110 bronze badges
1
Don't use$$...$$- that's deprecated
– ufo
Apr 16 at 12:00
2
how cantcolorboxbe incompatible withxcolor? It is automatically loaded when you suetcolorbox. There is no way to usetcolorboxwithoutxcolor
– ufo
Apr 16 at 12:03
@ufo the problem is not with xcolor per se but with color at pagebreaks.
– Ulrike Fischer
Apr 16 at 12:22
The local formatting breaks if the page breaks. It happens to me quite often that the local formatting by using something likeextras=colupper=redis lost once the pages breaks.
– HerculePoivrot
Apr 16 at 12:23
add a comment
|
1
Don't use$$...$$- that's deprecated
– ufo
Apr 16 at 12:00
2
how cantcolorboxbe incompatible withxcolor? It is automatically loaded when you suetcolorbox. There is no way to usetcolorboxwithoutxcolor
– ufo
Apr 16 at 12:03
@ufo the problem is not with xcolor per se but with color at pagebreaks.
– Ulrike Fischer
Apr 16 at 12:22
The local formatting breaks if the page breaks. It happens to me quite often that the local formatting by using something likeextras=colupper=redis lost once the pages breaks.
– HerculePoivrot
Apr 16 at 12:23
1
1
Don't use
$$...$$ - that's deprecated– ufo
Apr 16 at 12:00
Don't use
$$...$$ - that's deprecated– ufo
Apr 16 at 12:00
2
2
how can
tcolorbox be incompatible with xcolor? It is automatically loaded when you sue tcolorbox. There is no way to use tcolorbox without xcolor– ufo
Apr 16 at 12:03
how can
tcolorbox be incompatible with xcolor? It is automatically loaded when you sue tcolorbox. There is no way to use tcolorbox without xcolor– ufo
Apr 16 at 12:03
@ufo the problem is not with xcolor per se but with color at pagebreaks.
– Ulrike Fischer
Apr 16 at 12:22
@ufo the problem is not with xcolor per se but with color at pagebreaks.
– Ulrike Fischer
Apr 16 at 12:22
The local formatting breaks if the page breaks. It happens to me quite often that the local formatting by using something like
extras=colupper=red is lost once the pages breaks.– HerculePoivrot
Apr 16 at 12:23
The local formatting breaks if the page breaks. It happens to me quite often that the local formatting by using something like
extras=colupper=red is lost once the pages breaks.– HerculePoivrot
Apr 16 at 12:23
add a comment
|
2 Answers
2
active
oldest
votes
As it is rather improbable that there are page breaks in the math you could simply use color:
documentclassarticle
usepackagemathspec
setmainfontTeX Gyre Pagella
usepackageblindtext
usepackage[breakable]tcolorbox
begindocument
begintcolorbox[breakable]
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtextcolorbrown
[F=ma]
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtext
endtcolorbox
enddocument
With lualatex instead of xelatex you could use the luacolor package. This will solve both problems:
documentclassarticle
usepackageunicode-math
setmainfontTeX Gyre Pagella
setmathfontTeX Gyre Pagella Math
usepackageblindtext
usepackage[breakable]tcolorbox
usepackageluacolor
begindocument
begintcolorbox[breakable]
blindtext[3]
colorblue
blindtext[3]
colorred
blindtext
colorbrown
blindtext
[F=ma]
blindtext[3]
colorblue
blindtext[3]
colorred
blindtext
colorbrown
blindtext
endtcolorbox
enddocument
The pagebreaks is sometimes an issue, the main problem being that it's unpredictable. But the main issue is that I want conditional coloring of my text : a version for me and one for my students with some part of the text hidden, and therefore the maths must be the same colour than the main text. The LuaTeX solution works fine, but if possible I would like to avoid using it and stick to LaTeX or XeTex.
– HerculePoivrot
Apr 16 at 12:21
Sure I did understand this. But with the font method you will have to reset all math fonts before the math, addfontfeatures won't be taken into account. With unicode-math you could do something likesetmathfontTeX Gyre Pagella Math[Color=blue], I don't know if mathspec has something similar. With lualatex and luacolor it is really easier.
– Ulrike Fischer
Apr 16 at 12:30
Well I guess I will try with the LuaTex method which seems indeed very easy to use. Im always worried to change to LuaTeX because of the many documents I have running on regular LaTeX. Is there some kind of guide with the differences/advantages of those 3 computational modes (LaTeX, XeTeX and LuaTeX ?). Thanks for the answer anyway !
– HerculePoivrot
Apr 16 at 13:46
@HerculePoivrot there are several questions on the site about this, many of those questions are a bit old but you could look at for example tex.stackexchange.com/questions/126206/….
– Marijn
Apr 16 at 15:31
add a comment
|
With XeLaTeX, you could patch the math commands (both display and inline) to include the color command. This ensures that the color is set on the page where the math starts.
This does not work with the TeX commands $ and $$ but only with the LaTeX equivalents () and []. It also does not work if your math crosses a page break (but of course it will work if a new math expression starts on the next page). If you want to use it with other math-like environments (equation, align, etc) then you should patch those separately.
Note that you should set mycolor (or use boxcolor) before you use math, otherwise you'll get an error. Also note that this takes effect outside of the tcolorbox as well, so you should probably put defmycolorblack after each tcolorbox (or do that automatically with AtEndEnvironment).
With a small macro you can set color and addfontfeatures with a single command.
MWE:
documentclassarticle
usepackagemathspec
setmainfontLinux Libertine O
usepackageetoolbox
pretocmd[colormycolor
pretocmd(colormycolor
newcommandboxcolor[1]defmycolor#1addfontfeaturesColor=mycolor
usepackageblindtext
usepackage[breakable]tcolorbox
begindocument
begintcolorbox[breakable]
blindtext[3]
boxcolorred
blindtext[3]
boxcolororange
blindtext[3]
[F=mtimes a]
blindtext[3]
boxcolorblue
blindtext[3]
(1+1=2)
boxcolorred
blindtext
boxcolorbrown
blindtext
endtcolorbox
enddocument
Result:

Thank you for the answer. However, this will not work the way I want it to, because I have some regular math expressions (which should not colored) and a few documents of around 200 pages and I don't want to have to rework all of them with a special math mode, that would take way too much time. I will favor the LuaTeX version which will take less time I guess. But thanks for the detailled answer !
– HerculePoivrot
Apr 16 at 13:48
1
I understand that this solution can be a bit impractical at times, I just added it to have a XeLaTeX approach that is a bit more robust and automatic than setting the color yourself on every page. Note however that it is still possible to set the color at any time, so you can putcolorblackinside an expression that should not be colored. Also, the special math mode is actually not so special but should be default,$$as you used is actively discouraged (tex.stackexchange.com/questions/503/why-is-preferable-to) and$is still widely used but technically superseded by().
– Marijn
Apr 16 at 15:10
add a comment
|
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/4.0/"u003ecc by-sa 4.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%2f485130%2fcoloring-maths-inside-a-tcolorbox%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
As it is rather improbable that there are page breaks in the math you could simply use color:
documentclassarticle
usepackagemathspec
setmainfontTeX Gyre Pagella
usepackageblindtext
usepackage[breakable]tcolorbox
begindocument
begintcolorbox[breakable]
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtextcolorbrown
[F=ma]
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtext
endtcolorbox
enddocument
With lualatex instead of xelatex you could use the luacolor package. This will solve both problems:
documentclassarticle
usepackageunicode-math
setmainfontTeX Gyre Pagella
setmathfontTeX Gyre Pagella Math
usepackageblindtext
usepackage[breakable]tcolorbox
usepackageluacolor
begindocument
begintcolorbox[breakable]
blindtext[3]
colorblue
blindtext[3]
colorred
blindtext
colorbrown
blindtext
[F=ma]
blindtext[3]
colorblue
blindtext[3]
colorred
blindtext
colorbrown
blindtext
endtcolorbox
enddocument
The pagebreaks is sometimes an issue, the main problem being that it's unpredictable. But the main issue is that I want conditional coloring of my text : a version for me and one for my students with some part of the text hidden, and therefore the maths must be the same colour than the main text. The LuaTeX solution works fine, but if possible I would like to avoid using it and stick to LaTeX or XeTex.
– HerculePoivrot
Apr 16 at 12:21
Sure I did understand this. But with the font method you will have to reset all math fonts before the math, addfontfeatures won't be taken into account. With unicode-math you could do something likesetmathfontTeX Gyre Pagella Math[Color=blue], I don't know if mathspec has something similar. With lualatex and luacolor it is really easier.
– Ulrike Fischer
Apr 16 at 12:30
Well I guess I will try with the LuaTex method which seems indeed very easy to use. Im always worried to change to LuaTeX because of the many documents I have running on regular LaTeX. Is there some kind of guide with the differences/advantages of those 3 computational modes (LaTeX, XeTeX and LuaTeX ?). Thanks for the answer anyway !
– HerculePoivrot
Apr 16 at 13:46
@HerculePoivrot there are several questions on the site about this, many of those questions are a bit old but you could look at for example tex.stackexchange.com/questions/126206/….
– Marijn
Apr 16 at 15:31
add a comment
|
As it is rather improbable that there are page breaks in the math you could simply use color:
documentclassarticle
usepackagemathspec
setmainfontTeX Gyre Pagella
usepackageblindtext
usepackage[breakable]tcolorbox
begindocument
begintcolorbox[breakable]
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtextcolorbrown
[F=ma]
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtext
endtcolorbox
enddocument
With lualatex instead of xelatex you could use the luacolor package. This will solve both problems:
documentclassarticle
usepackageunicode-math
setmainfontTeX Gyre Pagella
setmathfontTeX Gyre Pagella Math
usepackageblindtext
usepackage[breakable]tcolorbox
usepackageluacolor
begindocument
begintcolorbox[breakable]
blindtext[3]
colorblue
blindtext[3]
colorred
blindtext
colorbrown
blindtext
[F=ma]
blindtext[3]
colorblue
blindtext[3]
colorred
blindtext
colorbrown
blindtext
endtcolorbox
enddocument
The pagebreaks is sometimes an issue, the main problem being that it's unpredictable. But the main issue is that I want conditional coloring of my text : a version for me and one for my students with some part of the text hidden, and therefore the maths must be the same colour than the main text. The LuaTeX solution works fine, but if possible I would like to avoid using it and stick to LaTeX or XeTex.
– HerculePoivrot
Apr 16 at 12:21
Sure I did understand this. But with the font method you will have to reset all math fonts before the math, addfontfeatures won't be taken into account. With unicode-math you could do something likesetmathfontTeX Gyre Pagella Math[Color=blue], I don't know if mathspec has something similar. With lualatex and luacolor it is really easier.
– Ulrike Fischer
Apr 16 at 12:30
Well I guess I will try with the LuaTex method which seems indeed very easy to use. Im always worried to change to LuaTeX because of the many documents I have running on regular LaTeX. Is there some kind of guide with the differences/advantages of those 3 computational modes (LaTeX, XeTeX and LuaTeX ?). Thanks for the answer anyway !
– HerculePoivrot
Apr 16 at 13:46
@HerculePoivrot there are several questions on the site about this, many of those questions are a bit old but you could look at for example tex.stackexchange.com/questions/126206/….
– Marijn
Apr 16 at 15:31
add a comment
|
As it is rather improbable that there are page breaks in the math you could simply use color:
documentclassarticle
usepackagemathspec
setmainfontTeX Gyre Pagella
usepackageblindtext
usepackage[breakable]tcolorbox
begindocument
begintcolorbox[breakable]
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtextcolorbrown
[F=ma]
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtext
endtcolorbox
enddocument
With lualatex instead of xelatex you could use the luacolor package. This will solve both problems:
documentclassarticle
usepackageunicode-math
setmainfontTeX Gyre Pagella
setmathfontTeX Gyre Pagella Math
usepackageblindtext
usepackage[breakable]tcolorbox
usepackageluacolor
begindocument
begintcolorbox[breakable]
blindtext[3]
colorblue
blindtext[3]
colorred
blindtext
colorbrown
blindtext
[F=ma]
blindtext[3]
colorblue
blindtext[3]
colorred
blindtext
colorbrown
blindtext
endtcolorbox
enddocument
As it is rather improbable that there are page breaks in the math you could simply use color:
documentclassarticle
usepackagemathspec
setmainfontTeX Gyre Pagella
usepackageblindtext
usepackage[breakable]tcolorbox
begindocument
begintcolorbox[breakable]
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtextcolorbrown
[F=ma]
blindtext[3]
addfontfeaturesColor=blue
blindtext[3]
addfontfeaturesColor=red
blindtext
addfontfeaturesColor=brown
blindtext
endtcolorbox
enddocument
With lualatex instead of xelatex you could use the luacolor package. This will solve both problems:
documentclassarticle
usepackageunicode-math
setmainfontTeX Gyre Pagella
setmathfontTeX Gyre Pagella Math
usepackageblindtext
usepackage[breakable]tcolorbox
usepackageluacolor
begindocument
begintcolorbox[breakable]
blindtext[3]
colorblue
blindtext[3]
colorred
blindtext
colorbrown
blindtext
[F=ma]
blindtext[3]
colorblue
blindtext[3]
colorred
blindtext
colorbrown
blindtext
endtcolorbox
enddocument
edited Apr 16 at 12:14
answered Apr 16 at 12:07
Ulrike FischerUlrike Fischer
217k9 gold badges325 silver badges726 bronze badges
217k9 gold badges325 silver badges726 bronze badges
The pagebreaks is sometimes an issue, the main problem being that it's unpredictable. But the main issue is that I want conditional coloring of my text : a version for me and one for my students with some part of the text hidden, and therefore the maths must be the same colour than the main text. The LuaTeX solution works fine, but if possible I would like to avoid using it and stick to LaTeX or XeTex.
– HerculePoivrot
Apr 16 at 12:21
Sure I did understand this. But with the font method you will have to reset all math fonts before the math, addfontfeatures won't be taken into account. With unicode-math you could do something likesetmathfontTeX Gyre Pagella Math[Color=blue], I don't know if mathspec has something similar. With lualatex and luacolor it is really easier.
– Ulrike Fischer
Apr 16 at 12:30
Well I guess I will try with the LuaTex method which seems indeed very easy to use. Im always worried to change to LuaTeX because of the many documents I have running on regular LaTeX. Is there some kind of guide with the differences/advantages of those 3 computational modes (LaTeX, XeTeX and LuaTeX ?). Thanks for the answer anyway !
– HerculePoivrot
Apr 16 at 13:46
@HerculePoivrot there are several questions on the site about this, many of those questions are a bit old but you could look at for example tex.stackexchange.com/questions/126206/….
– Marijn
Apr 16 at 15:31
add a comment
|
The pagebreaks is sometimes an issue, the main problem being that it's unpredictable. But the main issue is that I want conditional coloring of my text : a version for me and one for my students with some part of the text hidden, and therefore the maths must be the same colour than the main text. The LuaTeX solution works fine, but if possible I would like to avoid using it and stick to LaTeX or XeTex.
– HerculePoivrot
Apr 16 at 12:21
Sure I did understand this. But with the font method you will have to reset all math fonts before the math, addfontfeatures won't be taken into account. With unicode-math you could do something likesetmathfontTeX Gyre Pagella Math[Color=blue], I don't know if mathspec has something similar. With lualatex and luacolor it is really easier.
– Ulrike Fischer
Apr 16 at 12:30
Well I guess I will try with the LuaTex method which seems indeed very easy to use. Im always worried to change to LuaTeX because of the many documents I have running on regular LaTeX. Is there some kind of guide with the differences/advantages of those 3 computational modes (LaTeX, XeTeX and LuaTeX ?). Thanks for the answer anyway !
– HerculePoivrot
Apr 16 at 13:46
@HerculePoivrot there are several questions on the site about this, many of those questions are a bit old but you could look at for example tex.stackexchange.com/questions/126206/….
– Marijn
Apr 16 at 15:31
The pagebreaks is sometimes an issue, the main problem being that it's unpredictable. But the main issue is that I want conditional coloring of my text : a version for me and one for my students with some part of the text hidden, and therefore the maths must be the same colour than the main text. The LuaTeX solution works fine, but if possible I would like to avoid using it and stick to LaTeX or XeTex.
– HerculePoivrot
Apr 16 at 12:21
The pagebreaks is sometimes an issue, the main problem being that it's unpredictable. But the main issue is that I want conditional coloring of my text : a version for me and one for my students with some part of the text hidden, and therefore the maths must be the same colour than the main text. The LuaTeX solution works fine, but if possible I would like to avoid using it and stick to LaTeX or XeTex.
– HerculePoivrot
Apr 16 at 12:21
Sure I did understand this. But with the font method you will have to reset all math fonts before the math, addfontfeatures won't be taken into account. With unicode-math you could do something like
setmathfontTeX Gyre Pagella Math[Color=blue], I don't know if mathspec has something similar. With lualatex and luacolor it is really easier.– Ulrike Fischer
Apr 16 at 12:30
Sure I did understand this. But with the font method you will have to reset all math fonts before the math, addfontfeatures won't be taken into account. With unicode-math you could do something like
setmathfontTeX Gyre Pagella Math[Color=blue], I don't know if mathspec has something similar. With lualatex and luacolor it is really easier.– Ulrike Fischer
Apr 16 at 12:30
Well I guess I will try with the LuaTex method which seems indeed very easy to use. Im always worried to change to LuaTeX because of the many documents I have running on regular LaTeX. Is there some kind of guide with the differences/advantages of those 3 computational modes (LaTeX, XeTeX and LuaTeX ?). Thanks for the answer anyway !
– HerculePoivrot
Apr 16 at 13:46
Well I guess I will try with the LuaTex method which seems indeed very easy to use. Im always worried to change to LuaTeX because of the many documents I have running on regular LaTeX. Is there some kind of guide with the differences/advantages of those 3 computational modes (LaTeX, XeTeX and LuaTeX ?). Thanks for the answer anyway !
– HerculePoivrot
Apr 16 at 13:46
@HerculePoivrot there are several questions on the site about this, many of those questions are a bit old but you could look at for example tex.stackexchange.com/questions/126206/….
– Marijn
Apr 16 at 15:31
@HerculePoivrot there are several questions on the site about this, many of those questions are a bit old but you could look at for example tex.stackexchange.com/questions/126206/….
– Marijn
Apr 16 at 15:31
add a comment
|
With XeLaTeX, you could patch the math commands (both display and inline) to include the color command. This ensures that the color is set on the page where the math starts.
This does not work with the TeX commands $ and $$ but only with the LaTeX equivalents () and []. It also does not work if your math crosses a page break (but of course it will work if a new math expression starts on the next page). If you want to use it with other math-like environments (equation, align, etc) then you should patch those separately.
Note that you should set mycolor (or use boxcolor) before you use math, otherwise you'll get an error. Also note that this takes effect outside of the tcolorbox as well, so you should probably put defmycolorblack after each tcolorbox (or do that automatically with AtEndEnvironment).
With a small macro you can set color and addfontfeatures with a single command.
MWE:
documentclassarticle
usepackagemathspec
setmainfontLinux Libertine O
usepackageetoolbox
pretocmd[colormycolor
pretocmd(colormycolor
newcommandboxcolor[1]defmycolor#1addfontfeaturesColor=mycolor
usepackageblindtext
usepackage[breakable]tcolorbox
begindocument
begintcolorbox[breakable]
blindtext[3]
boxcolorred
blindtext[3]
boxcolororange
blindtext[3]
[F=mtimes a]
blindtext[3]
boxcolorblue
blindtext[3]
(1+1=2)
boxcolorred
blindtext
boxcolorbrown
blindtext
endtcolorbox
enddocument
Result:

Thank you for the answer. However, this will not work the way I want it to, because I have some regular math expressions (which should not colored) and a few documents of around 200 pages and I don't want to have to rework all of them with a special math mode, that would take way too much time. I will favor the LuaTeX version which will take less time I guess. But thanks for the detailled answer !
– HerculePoivrot
Apr 16 at 13:48
1
I understand that this solution can be a bit impractical at times, I just added it to have a XeLaTeX approach that is a bit more robust and automatic than setting the color yourself on every page. Note however that it is still possible to set the color at any time, so you can putcolorblackinside an expression that should not be colored. Also, the special math mode is actually not so special but should be default,$$as you used is actively discouraged (tex.stackexchange.com/questions/503/why-is-preferable-to) and$is still widely used but technically superseded by().
– Marijn
Apr 16 at 15:10
add a comment
|
With XeLaTeX, you could patch the math commands (both display and inline) to include the color command. This ensures that the color is set on the page where the math starts.
This does not work with the TeX commands $ and $$ but only with the LaTeX equivalents () and []. It also does not work if your math crosses a page break (but of course it will work if a new math expression starts on the next page). If you want to use it with other math-like environments (equation, align, etc) then you should patch those separately.
Note that you should set mycolor (or use boxcolor) before you use math, otherwise you'll get an error. Also note that this takes effect outside of the tcolorbox as well, so you should probably put defmycolorblack after each tcolorbox (or do that automatically with AtEndEnvironment).
With a small macro you can set color and addfontfeatures with a single command.
MWE:
documentclassarticle
usepackagemathspec
setmainfontLinux Libertine O
usepackageetoolbox
pretocmd[colormycolor
pretocmd(colormycolor
newcommandboxcolor[1]defmycolor#1addfontfeaturesColor=mycolor
usepackageblindtext
usepackage[breakable]tcolorbox
begindocument
begintcolorbox[breakable]
blindtext[3]
boxcolorred
blindtext[3]
boxcolororange
blindtext[3]
[F=mtimes a]
blindtext[3]
boxcolorblue
blindtext[3]
(1+1=2)
boxcolorred
blindtext
boxcolorbrown
blindtext
endtcolorbox
enddocument
Result:

Thank you for the answer. However, this will not work the way I want it to, because I have some regular math expressions (which should not colored) and a few documents of around 200 pages and I don't want to have to rework all of them with a special math mode, that would take way too much time. I will favor the LuaTeX version which will take less time I guess. But thanks for the detailled answer !
– HerculePoivrot
Apr 16 at 13:48
1
I understand that this solution can be a bit impractical at times, I just added it to have a XeLaTeX approach that is a bit more robust and automatic than setting the color yourself on every page. Note however that it is still possible to set the color at any time, so you can putcolorblackinside an expression that should not be colored. Also, the special math mode is actually not so special but should be default,$$as you used is actively discouraged (tex.stackexchange.com/questions/503/why-is-preferable-to) and$is still widely used but technically superseded by().
– Marijn
Apr 16 at 15:10
add a comment
|
With XeLaTeX, you could patch the math commands (both display and inline) to include the color command. This ensures that the color is set on the page where the math starts.
This does not work with the TeX commands $ and $$ but only with the LaTeX equivalents () and []. It also does not work if your math crosses a page break (but of course it will work if a new math expression starts on the next page). If you want to use it with other math-like environments (equation, align, etc) then you should patch those separately.
Note that you should set mycolor (or use boxcolor) before you use math, otherwise you'll get an error. Also note that this takes effect outside of the tcolorbox as well, so you should probably put defmycolorblack after each tcolorbox (or do that automatically with AtEndEnvironment).
With a small macro you can set color and addfontfeatures with a single command.
MWE:
documentclassarticle
usepackagemathspec
setmainfontLinux Libertine O
usepackageetoolbox
pretocmd[colormycolor
pretocmd(colormycolor
newcommandboxcolor[1]defmycolor#1addfontfeaturesColor=mycolor
usepackageblindtext
usepackage[breakable]tcolorbox
begindocument
begintcolorbox[breakable]
blindtext[3]
boxcolorred
blindtext[3]
boxcolororange
blindtext[3]
[F=mtimes a]
blindtext[3]
boxcolorblue
blindtext[3]
(1+1=2)
boxcolorred
blindtext
boxcolorbrown
blindtext
endtcolorbox
enddocument
Result:

With XeLaTeX, you could patch the math commands (both display and inline) to include the color command. This ensures that the color is set on the page where the math starts.
This does not work with the TeX commands $ and $$ but only with the LaTeX equivalents () and []. It also does not work if your math crosses a page break (but of course it will work if a new math expression starts on the next page). If you want to use it with other math-like environments (equation, align, etc) then you should patch those separately.
Note that you should set mycolor (or use boxcolor) before you use math, otherwise you'll get an error. Also note that this takes effect outside of the tcolorbox as well, so you should probably put defmycolorblack after each tcolorbox (or do that automatically with AtEndEnvironment).
With a small macro you can set color and addfontfeatures with a single command.
MWE:
documentclassarticle
usepackagemathspec
setmainfontLinux Libertine O
usepackageetoolbox
pretocmd[colormycolor
pretocmd(colormycolor
newcommandboxcolor[1]defmycolor#1addfontfeaturesColor=mycolor
usepackageblindtext
usepackage[breakable]tcolorbox
begindocument
begintcolorbox[breakable]
blindtext[3]
boxcolorred
blindtext[3]
boxcolororange
blindtext[3]
[F=mtimes a]
blindtext[3]
boxcolorblue
blindtext[3]
(1+1=2)
boxcolorred
blindtext
boxcolorbrown
blindtext
endtcolorbox
enddocument
Result:

edited Apr 16 at 13:30
answered Apr 16 at 13:24
MarijnMarijn
13k1 gold badge7 silver badges42 bronze badges
13k1 gold badge7 silver badges42 bronze badges
Thank you for the answer. However, this will not work the way I want it to, because I have some regular math expressions (which should not colored) and a few documents of around 200 pages and I don't want to have to rework all of them with a special math mode, that would take way too much time. I will favor the LuaTeX version which will take less time I guess. But thanks for the detailled answer !
– HerculePoivrot
Apr 16 at 13:48
1
I understand that this solution can be a bit impractical at times, I just added it to have a XeLaTeX approach that is a bit more robust and automatic than setting the color yourself on every page. Note however that it is still possible to set the color at any time, so you can putcolorblackinside an expression that should not be colored. Also, the special math mode is actually not so special but should be default,$$as you used is actively discouraged (tex.stackexchange.com/questions/503/why-is-preferable-to) and$is still widely used but technically superseded by().
– Marijn
Apr 16 at 15:10
add a comment
|
Thank you for the answer. However, this will not work the way I want it to, because I have some regular math expressions (which should not colored) and a few documents of around 200 pages and I don't want to have to rework all of them with a special math mode, that would take way too much time. I will favor the LuaTeX version which will take less time I guess. But thanks for the detailled answer !
– HerculePoivrot
Apr 16 at 13:48
1
I understand that this solution can be a bit impractical at times, I just added it to have a XeLaTeX approach that is a bit more robust and automatic than setting the color yourself on every page. Note however that it is still possible to set the color at any time, so you can putcolorblackinside an expression that should not be colored. Also, the special math mode is actually not so special but should be default,$$as you used is actively discouraged (tex.stackexchange.com/questions/503/why-is-preferable-to) and$is still widely used but technically superseded by().
– Marijn
Apr 16 at 15:10
Thank you for the answer. However, this will not work the way I want it to, because I have some regular math expressions (which should not colored) and a few documents of around 200 pages and I don't want to have to rework all of them with a special math mode, that would take way too much time. I will favor the LuaTeX version which will take less time I guess. But thanks for the detailled answer !
– HerculePoivrot
Apr 16 at 13:48
Thank you for the answer. However, this will not work the way I want it to, because I have some regular math expressions (which should not colored) and a few documents of around 200 pages and I don't want to have to rework all of them with a special math mode, that would take way too much time. I will favor the LuaTeX version which will take less time I guess. But thanks for the detailled answer !
– HerculePoivrot
Apr 16 at 13:48
1
1
I understand that this solution can be a bit impractical at times, I just added it to have a XeLaTeX approach that is a bit more robust and automatic than setting the color yourself on every page. Note however that it is still possible to set the color at any time, so you can put
colorblack inside an expression that should not be colored. Also, the special math mode is actually not so special but should be default, $$ as you used is actively discouraged (tex.stackexchange.com/questions/503/why-is-preferable-to) and $ is still widely used but technically superseded by ().– Marijn
Apr 16 at 15:10
I understand that this solution can be a bit impractical at times, I just added it to have a XeLaTeX approach that is a bit more robust and automatic than setting the color yourself on every page. Note however that it is still possible to set the color at any time, so you can put
colorblack inside an expression that should not be colored. Also, the special math mode is actually not so special but should be default, $$ as you used is actively discouraged (tex.stackexchange.com/questions/503/why-is-preferable-to) and $ is still widely used but technically superseded by ().– Marijn
Apr 16 at 15:10
add a comment
|
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.
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%2f485130%2fcoloring-maths-inside-a-tcolorbox%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
Don't use
$$...$$- that's deprecated– ufo
Apr 16 at 12:00
2
how can
tcolorboxbe incompatible withxcolor? It is automatically loaded when you suetcolorbox. There is no way to usetcolorboxwithoutxcolor– ufo
Apr 16 at 12:03
@ufo the problem is not with xcolor per se but with color at pagebreaks.
– Ulrike Fischer
Apr 16 at 12:22
The local formatting breaks if the page breaks. It happens to me quite often that the local formatting by using something like
extras=colupper=redis lost once the pages breaks.– HerculePoivrot
Apr 16 at 12:23