我试图在数学模式下对齐表达式的内容。笔记:我见过很多与此类似的问题,但我问的不是块内的对齐equation
。换句话说,我希望我的公式插入到行中:在这个范围内,我使用 $$ 在文本中划定公式但当 $$ 内的表达式太长时,它会进一步进行垂直对齐,并且仅在终止时插入新行。
编辑:来自我的文档:
\documentclass{article}
\begin{document}
[...]then, adding a version counter would turn such policy into "$ECU\_MODEL\_2247\_v\_0 \; \textbf{OR} \; \textbf{(} CAR\_MODEL\_21\_v\_0 \; \textbf{AND} \; ECU\_MODEL\_2248\_v\_0 \textbf{)}$". If a key now gets compromised, then the manufacturer updates the version of the access policy, that now becomes "$ECU\_MODEL\_2247\_v\_1 \; \textbf{OR} \; \textbf{(} CAR\_MODEL\_21\_v\_1 \; \textbf{AND} \; ECU\_MODEL\_2248\_v\_1 \textbf{)}$"[...]
\end{document}
$$ 内的文本超出了对齐范围,但我不想将其放在方程块因为我希望它像我报告的文档中一样“内联”。
答案1
我建议您加载该xurl
包并使用其\path
宏来排版长名称标签。这样,长标签内的换行符就可以在需要的地方出现。(该\path
宏与宏密切相关\url
;唯一的真正区别是它hyperref
不会尝试将参数变成\path
可点击的 URL 字符串。)
此外,我还建议你不要粗体AND 和 OR 术语;相反,考虑用小型大写字母排版它们。
\documentclass{article}
\usepackage[T1]{fontenc} % for robust-looking _ (underscore) characters
\usepackage{xurl}
\newcommand\logic[1]{\textsc{\MakeLowercase{#1}}}
\begin{document}
\noindent
[\dots] then, adding a version counter would turn such policy into
``\path{ECU_MODEL_2247_v_0} \logic{OR} (\path{CAR_MODEL_21_v_0}
\logic{AND} \path{ECU_MODEL_2248_v_0})''.
If a key now gets compromised, then the manufacturer updates the
version of the access policy, which now becomes
``\path{ECU_MODEL_2247_v_1} \logic{OR} (\path{CAR_MODEL_21_v_1}
\logic{AND} \path{ECU_MODEL_2248_v_1})'' [\dots]
\end{document}
附录:当然,以显示格式排版较长的表达式很可能会使它们更易于阅读,无论是否出现换行符。
至少对于我这个外行人来说,单独显示行上的表达式可以更轻松地来回浏览并弄清楚先决条件和后置条件。
\documentclass{article}
\usepackage[T1]{fontenc} % for robust-looking _ (underscore) characters
\usepackage{xurl}
\newcommand\logic[1]{\textsc{\MakeLowercase{#1}}}
\begin{document}
\noindent
[\dots] then, adding a version counter would turn such policy into
\begin{center}
\path{ECU_MODEL_2247_v_0} \logic{OR} (\path{CAR_MODEL_21_v_0}
\logic{AND} \path{ECU_MODEL_2248_v_0})\,.
\end{center}
If a key now gets compromised, then the manufacturer updates
the version of the access policy, which now becomes
\begin{center}
\path{ECU_MODEL_2247_v_1} \logic{OR} (\path{CAR_MODEL_21_v_1}
\logic{AND} \path{ECU_MODEL_2248_v_1})\,.
\end{center}
[\dots]
\end{document}
答案2
您的示例不需要数学模式,因为它不包含数学材料。但是,如果表达式包含真正的数学材料并且您需要在 中强制换行$...$
,则可以使用\allowbreak
。
\documentclass{article}
\begin{document}
[...]then, adding a version counter would turn such policy into
"$ECU\_MODEL\allowbreak
\_2247\_v\_0 \; \textbf{OR} \; \textbf{(}
CAR\_MODEL\_21\_v\_0 \; \textbf{AND} \; ECU\_MODEL\_2248\_v\_0 \textbf{)}$".
If a key now gets compromised, then the manufacturer updates the version of
the access policy, that now becomes "$ECU\_MODEL\_2247\_v\_1 \; \textbf{OR} \;
\textbf{(} CAR\_MODEL\allowbreak
\_21\_v\_1 \; \textbf{AND} \;
ECU\_MODEL\_2248\_v\_1 \textbf{)}$"[...]
\end{document}