ifthen:用更长的字符串替换固定环境中的单个字符

ifthen:用更长的字符串替换固定环境中的单个字符

我们使用自定义命令来突出显示系统属性:

\newcommand{\propDesc}[2]{
\fcolorbox{white}{propbg}{
\begin{minipage}[c]{\textwidth}
\vspace{1ex}
\textcolor{title}{#1}
\\
#2 
\vspace{1ex}
\end{minipage}
}
\\
}

标题(#1)以蓝色突出显示(强调)。描述(#2)是纯文本。这些属性中的大多数包括一个,_它被手动替换为一个\_。因此,某些_属性变成了某些\_属性才能进行编译。这很烦人。我的目标是找到一种方法,允许我_自动替换所有,而不必更改现有的\_。因此,我只需使用复制和粘贴即可添加新属性。类似于如果_那么\_,否则什么也不做或简单地\_。如果一直在使用一些基本的ifthen命令。但是,我无法找到/编写可以完成工作的命令。我需要一个可以替换所有_\propDesc命令而不会受到现有命令干扰的命令\_

答案1

您可以_用 来替换\_,但这样做可能更简单_

此外,您还有多个额外的空间,这将产生过满的盒子或异常的垂直间距,因为它们必须与盒子位于同一行\textwidth

\newcommand{\propDesc}[2]{%%%%%%%%%%%%%%%
\fcolorbox{white}{propbg}{%%%%%%%%%%%%%%%
\begin{minipage}[c]{\textwidth}%%%%%%%%%%%%
\vspace{1ex}%%%%%%%%%%%%%%%%
\textcolor{title}{#1}%%%%%%%%%%%%%%%%%
\\%%%%%%%%%%%%%%%%%%%%
#2%%%%%%%%%%%%%%%
  \par% always put \par or a blank line before vspace
\vspace{1ex}%%%%%%%%%%%%%%%%%%%%%%%
\end{minipage}%%%%%%%%%%%%%%%%%%
}%%%%%%%%%%%%%%%%%%%%%%%
\\% almost certainly should be `\par` `\\ ` other than in tables is usually wrong.
}

要修复_类似的问题

\usepackage[T1]{fontenc}

\newcommand\propDesc{\begingroup\catcode`\_=12 % make _ a normal character
\newcommand{\xpropDesc}[2]{\endgroup%%%%%%%%%%%%%%%
\fcolorbox{white}{propbg}{%%%%%%%%%%%%%%%
\begin{minipage}[c]{\textwidth}%%%%%%%%%%%%
\vspace{1ex}%%%%%%%%%%%%%%%%
\textcolor{title}{#1}%%%%%%%%%%%%%%%%%
\\%%%%%%%%%%%%%%%%%%%%
#2%%%%%%%%%%%%%%%
  \par% always put \par or a blank line before vspace
\vspace{1ex}%%%%%%%%%%%%%%%%%%%%%%%
\end{minipage}%%%%%%%%%%%%%%%%%%
}%%%%%%%%%%%%%%%%%%%%%%%
\\% almost certainly should be `\par` `\\ ` other than in tables is usually wrong.
}

如果您需要在数学中使用下标,那么您不能使用其中一个参数,_因此您必须使用\sb

相关内容