是否可以在 LaTeX 文本中转义“%”符号?

是否可以在 LaTeX 文本中转义“%”符号?
\usepackage{drawstack}

\newcommand{\celladdr}[1]{
  \draw[<-,line width=0.7pt] (0,\value{cellnb}-0.5) +(2,\value{ptrnb}*0.1) -- +(2.5,\value{ptrnb}*0.45);
  \draw (2.5,\value{ptrnb}*0.5+\value{cellnb}) node[anchor=north west,yshift=-1.6ex] {\mintinline{py}{#1}};
}

\newcommand{\finishframev}[1]{
  \draw[snake=brace, line width=0.6pt, segment amplitude=7pt]
  (-2,\value{cellnb}-0.5) -- (-2,\value{startframe}-0.5);
  \node[label=left:\rotatebox{90}{#1}] at (-2.2cm,\value{cellnb}*0.5+\value{startframe}*0.5-0.5) {};
}
\item Stack Diagram: \\
\begin{drawstack}
%   Within the environment, draw stack elements with 
  \startframe
  \cell{RIP} \celladdr{0xff}
  \cell{SFP} \celladdr{ESP}
  \padding{1}{compiler padding}
  \cell{buf[8]} \celladdr{(\%ESP)-20} \cellcom{(This cell not to scale)}
  \finishframev{display}
\end{drawstack}

打印出: 在此处输入图片描述

如果我不包含反斜杠,Overleaf 将无法编译。我该如何获取%ESP

答案1

您正在传递这些字符串,\mintinline以便由 Pygments 控制输出。

%最简单的解决方案是在环境持续期间禁用注释字符。

\documentclass{article}
\usepackage{drawstack}
\usepackage{minted}

\newcommand{\celladdr}[1]{%
  \draw[<-,line width=0.7pt]
    (0,\value{cellnb}-0.5)+(2,\value{ptrnb}*0.1) -- +(2.5,\value{ptrnb}*0.45);
  \draw (2.5,\value{ptrnb}*0.5+\value{cellnb}) 
    node[anchor=north west,yshift=-1.6ex] {\mintinline{py}{#1}};
}

\newcommand{\finishframev}[1]{%
  \draw[snake=brace, line width=0.6pt, segment amplitude=7pt]
    (-2,\value{cellnb}-0.5) -- (-2,\value{startframe}-0.5);
  \node[label=left:\rotatebox{90}{#1}]
    at (-2.2cm,\value{cellnb}*0.5+\value{startframe}*0.5-0.5) {};
}

\begin{document}
\begin{drawstack}\catcode`\%=12
  \startframe
  \cell{RIP} \celladdr{0xff}
  \cell{SFP} \celladdr{ESP}
  \padding{1}{compiler padding}
  \cell{buf[8]} \celladdr{(%ESP)-20} \cellcom{(This cell not to scale)}
  \finishframev{display}
\end{drawstack}

\end{document}

当然,在那种环境下你不能发表评论。

在此处输入图片描述

相关内容