![维度计算使用 newdimen - LaTeX 读取我的方程的部分内容](https://linux22.com/image/290685/%E7%BB%B4%E5%BA%A6%E8%AE%A1%E7%AE%97%E4%BD%BF%E7%94%A8%20newdimen%20-%20LaTeX%20%E8%AF%BB%E5%8F%96%E6%88%91%E7%9A%84%E6%96%B9%E7%A8%8B%E7%9A%84%E9%83%A8%E5%88%86%E5%86%85%E5%AE%B9.png)
我正在尝试进行维度计算,但 LaTeX 读取了我的方程式的某些部分。我BLLa
该如何正确计算?
抱歉,这个例子不够简洁。
\documentclass{article}
\usepackage{etex}
\usepackage{etoolbox}
\usepackage{minted}
\usepackage[skins]{tcolorbox}
\usepackage{lineno}
\makeatletter
\def\gobble#1{}
\renewcommand\DeleteFile[1]{}
\definecolor{mintedbg}{HTML}{F8FAFF}
\definecolor{col1}{HTML}{80B2FF} %4 Outer right borderline
\definecolor{col2}{HTML}{99C2FF} %3
\definecolor{col3}{HTML}{B2D1FF} %2
\definecolor{col4}{HTML}{CCE0FF} %1 Outer left borderline
\newdimen\BLW
\BLW\dimexpr 3pt\relax
\newdimen\BLS
\BLS\dimexpr .5pt\relax
\newdimen\BLLa
\BLLa\dimexpr -.5\BLW-\BLS-.5 *.75\BLW \relax
\newdimen\BLLb
\BLLb\dimexpr -.5\BLW-\BLS-.5(.75\BLW)-\BLS-.5(.75^2 \BLW)\relax
\BeforeBeginEnvironment{Rcode}{%
\begin{trivlist}
\item\begin{tcolorbox}[
width=\linewidth-6pt,
enlarge top by=3pt,
enlarge bottom by=3pt,
enlarge left by=3pt,
enlarge right by=3pt,
frame hidden,boxrule=0pt,
top=1mm,
bottom=1mm,
colback=mintedbg,
freelance,
arc=0pt,
outer arc=0pt,
boxrule=0pt,
frame code={
\draw[col1,line width=\BLW] % right
([xshift=0pt]frame.north west) -- ([xshift=0pt]frame.south west);
\draw[col2,line width=\BLW*(3/4)]
([xshift=\BLLa]frame.north west) -- ([xshift=\BLLa]frame.south west);
\draw[col3,line width=\BLW*(3/4)^2]
([xshift=\BLLb]frame.north west) -- ([xshift=\BLLb]frame.south west);
\draw[col4,line width=\BLW*(3/4)^3]
([xshift=-7.5pt]frame.north west) -- ([xshift=-7.5pt]frame.south west);
}
]}
\AfterEndEnvironment{Rcode}{\end{tcolorbox}\end{trivlist}}%
\pgfkeys{
/terminal/.cd,
caption/.code={\pgfkeyssetvalue{terminal/caption}{\caption{#1}}}, % Double hash for expansion
label/.code={\pgfkeyssetvalue{terminal/label}{\label{#1}}},
}
\pgfkeyssetvalue{terminal/label}{}
\pgfkeyssetvalue{terminal/caption}{\caption{}}
\newenvironment{Rcode}{%
\VerbatimEnvironment
\minted@resetoptions
\setkeys{minted@opt}{}
\begin{center}
\begin{minipage}{\linewidth}
\begin{VerbatimOut}{\jobname.pyg}}
{%
\end{VerbatimOut}
\minted@pygmentize{r}
\DeleteFile{\jobname.pyg}
\end{minipage}
\end{center}}
\makeatother
\begin{document}
\begin{Rcode}
# Here a piece of R code that we've
# all come to know and love
object <- c(1,2,5,8)
\end{Rcode}
\end{document}
我知道 LaTeX 会一直扩展到\BLW
(*.75 之后),但我不知道如何阻止 LaTeX 读取并丢弃 *.75。
答案1
允许使用扩展语法xintexpr。
只需将您的表达式包装为\dimexpr\xinttheiexpr <stuff>\relax sp\relax
。
\documentclass{article}
\usepackage{xintexpr}
\newdimen\BLW
\BLW\dimexpr 3pt\relax
\newdimen\BLS
\BLS\dimexpr .5pt\relax
\newdimen\BLLa
\BLLa\dimexpr\xinttheiexpr -.5\BLW-\BLS-.5 *.75\BLW\relax sp\relax
\newdimen\BLLb
\BLLb\dimexpr\xinttheiexpr -.5\BLW-\BLS-.5(.75\BLW)-\BLS-.5(.75^2 \BLW)\relax sp\relax
\begin{document}
\the\BLW
\the\BLS
\the\BLLa
\the\BLLb
\end{document}
答案2
\dimexpr
语法非常受限,因为它基本上对一系列\advance
、\multiply
和\divide
语句进行编码。
texdoc etex
应该产生一个包含正式语法的文档。
如果是
\BLLa\dimexpr -.5\BLW-\BLS-.5 *.75\BLW \relax
你不能直接用无量纲分数乘以某个数。事实上,像这样的分数.5
表达式仅有的允许作为长度或跳过寄存器(或\dimexpr
)的前缀。因此允许的替代方案是
\BLLa\dimexpr -.5\BLW-\BLS-.5\dimexpr.75\BLW\relax \relax
\BLLa\dimexpr -.5\BLW-\BLS-.75\BLW/2 \relax
\BLLa\dimexpr -.5\BLW-\BLS-.375\BLW \relax