答案1
看附录进行修改以反映 OP 澄清的问题。
这里我介绍了\margcmd
采用宏名(不带反斜杠)并在 marginpar 框中右对齐,以反斜杠为前导,并使用\ttfamily
。
Manuel 还提出了建议,使用\string
,这样你就可以在调用本身中包含反斜杠,并且 [可选] 省略括号。我称他的建议\manuelcmd
最后一个案例中显示的另一种选择是\marginpar{\hfill\textbackslash lastmacro}
,它已经体现在\acommand
宏中。
\documentclass{article}
\newcommand\margcmd[1]{\marginpar{\hfill\ttfamily\char'134#1}}
\newcommand*\manuelcmd[1]{\marginpar{\hfill\ttfamily\string#1}}
\newcommand\acommand[1]{\marginpar{\hfill\textbackslash #1}}
\reversemarginpar
\begin{document}
This is a test.\margcmd{mymacro}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
This is a test.\manuelcmd{\nextmacro}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
This is a test.\acommand{nothermacro}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{document}
附录
为了处理左边距上的宏名称和\marginpar
右边距上的其他名称,我采用了另一种机制来设置左侧宏名称,即包。我使用一种方法tabto
创建了一个类似于的宏\marginpar
,称为。然后,我可以自由地在右侧设置实际文本,同时在左侧设置宏名称。\mpar
tabto
\marginpar
\documentclass{article}
\usepackage{tabto}
\newcommand\mpar[1]{\leavevmode\tabto*{-1in}\makebox[.8in]{#1}%
\tabto*{\TabPrevPos}}
\newcommand\margcmd[1]{\mpar{\hfill\ttfamily\char'134#1}}
\newcommand*\manuelcmd[1]{\mpar{\hfill\ttfamily\string#1}}
\newcommand\acommand[1]{\mpar{\hfill\textbackslash #1}}
\begin{document}
This\marginpar{This is my marginpar, the first} is a test. \margcmd{mymacro}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
This is a test.\manuelcmd{\nextmacro}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
This\marginpar{My last and final marginpar} is a test. \acommand{nothermacro}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{document}