投影机中的彩色数学

投影机中的彩色数学

我有一个问题:有没有办法让数学($s 之间的所有内容)与文本(例如green)的颜色不同beamer

答案1

Beamer 已内置此功能。Beamer colorsmath text及其子元素math text inlinedmath text displayednormal text in math text控制 Beamer 文档中数学的颜色。Beamer 手册(版本 3.12)第 17.3 节有更多详细信息,请注意它们带有两个警告:一个是“考虑不这样做”警告,另一个是“实施可能会中断”警告。

另一种方法更为稳健,但与投影机内部颜色材料交互效果较差,即使用unicode-math包(需要lualatexxelatex)加载具有指定颜色的数学字体。请参阅 Will Robertson 对我的问题的回答我可以永久改变字母的字体和颜色吗?有关详细信息。交互作用减弱的地方表现在诸如 beamer 中部分可见的文本之类的东西上:这是通过在解析文本时混合颜色来完成的,但unicode-math颜色在开始时就设置好了,因此以后不能淡化。(顺便说一下,这是我为此使用的解决方案。为了解决这个交互问题 - 我很少遇到 - 我通过覆盖部分透明的块而不是混合颜色来淡化事物。)

答案2

这是 LuaTeX 中使用正则表达式的片段。我们通过两个 TeX 命令手动激活和停用搜索,在选定的部分中我们搜索$...$,但既不搜索$$...$$也不搜索\$。似乎使用此方法我们可以即时修改文档的几乎任何部分。

如果不使用 LuaTeX,我们可以提取那些选定的部分,修改它们并在运行中或在 TeX 运行后将它们返回到主 TeX 引擎(相同的方法使用外部工具,如 MakeIndex、Xindy 等)。

我附上了代码(我们运行lualatex mal-inline-math.tex)及其输出。

% lualatex mal-inline-math.tex
\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{luacode}
\usepackage{xcolor}

\begin{document}
\begin{luacode*}
function colorit() -- the core of the algorithm
math=tex.toks[0] -- take data from TeX to Lua
math=unicode.utf8.gsub(math, "([^%$\\])(%$[^%$]+[^%$\\]%$)", "%1{\\color{blue}%2}") -- regular expression, a try to find $...$ without $$...$$ and withtou a dollar sign
print(math) -- print the result to the terminal
tex.print(math) -- typeset the result in TeX
end -- function, colorit
\end{luacode*}

% pass an argument to Lua
\def\colorit#1\endcolorit{\toks0{#1}\directlua{colorit()}}

Untouched part: $k+l+m$.\par
\colorit % color inline mathematics, if found
Some text. $a+b+c$. \$ and some mathematics. 
$$d+e+f,$$ $x+y+z$.
Next part of the document.
\endcolorit % stop searching for inline mathematics
\end{document}

使用示例

相关内容