我创建了这个新命令\boldAcr
:
\makeatletter % we need to use kernel commands
\newcommand{\boldAcr[1]}{\MakeTextUppercase{\textbf{#1}}\@boldAcrOne}
\newcommand\@boldAcrOne{\@ifnextchar\stopBold{\@boldSend}{\@boldAcrTwo}}
\newcommand\@boldAcrTwo[1]{\@boldAcrThree{#1}\@boldAcrOne%restart the recursion
}
\newcommand\@boldAcrThree[1]{ \fb{#1}} %Space
\newcommand\@boldSend[1]{% The argument is \stopBold
}
\makeatother
\newcommand{\fb}[1]{\dofb#1}
\newcommand{\dofb}[1]{\MakeTextUppercase{\textbf{#1}}}
我这样称呼它:
\boldAcr[owasp] {open} {web} {application} {security} {project} \stopBold \\
\boldAcr[xss] {cross} {site} {scripting} \stopBold \\
答案1
我想我应该使用更简单的输入语法
\documentclass{article}
\def\boldAcr#1 {\makebox[2cm][l]{\textbf{\MakeUppercase{#1}}} \boldAcrB}
\def\boldAcrB#1 {\ifx\\#1\par\else\boldAcrC#1 \expandafter\boldAcrB\fi}
\def\boldAcrC#1{\textbf{\MakeUppercase{#1}}}
\begin{document}
\boldAcr owasp open web application security project \\
\boldAcr xss cross site scripting \\
\end{document}
答案2
你可以做得更好xparse
:
\documentclass{article}
\usepackage{xparse}
\newlength{\boldAcrwidth}
\setlength{\boldAcrwidth}{2cm}
\NewDocumentCommand{\boldAcr}{m >{\SplitList{ }}m}{%
\makebox[\boldAcrwidth][l]{\bfseries\MakeUppercase{#1}}%
\ProcessList{#2}{\boldAcrFirst}%
\unskip
}
\NewDocumentCommand{\boldAcrFirst}{m}{%
\boldAcrFirstAux#1 % we want a space
}
\NewDocumentCommand{\boldAcrFirstAux}{m}{%
\textbf{\MakeUppercase{#1}}%
}
\begin{document}
\begin{flushleft}
\boldAcr{owasp}{open web application security project} \\
\boldAcr{xss}{cross site scripting} \\
\end{flushleft}
\end{document}
第二个参数以空格分隔;每个项目都传递给\boldAcrFirst
简单调用的宏\boldAcrFirstAux
,该宏仅使用第一个字母,将其变为粗体和大写,其余部分正常排版并添加尾随空格。最后一个空格被删除\unskip
。