考虑以下代码片段:
a) 使用命令在某些文档中打印文本\defPrimitiveRoots
\Snippet{\defPrimitiveRoots}{Integers with primitive roots}{
Let $n,k$ be integers, and $p$ a prime. Then $n$ possesses primitive roots if and only if $n$ is of the form $2, 4, p^k$ or $2p^k$.
}
b) 进一步呼吁\srem
\newcommand{\Snippet}[3]{
\newcommand{#1}{
\srem{#2}{
#3
}
}
}
c) 进一步呼吁保护\shadedrem
环境。
\newcommand{\srem}[2]{
\begin{shadedrem}
\textbf{#1} \newline #2
\end{shadedrem}
}
最后,在文档中,文本被写入
\defPrimitiveRoots
我想要自动生成两个命令 1) \cshPrimitiveRoots
(与 相同\defPrimitiveRoots above
)和 2)\beaPrimitiveRoots
其中文本被格式化以便它可以很好地打印在beamer
幻灯片上。
问题:我想我必须更改这部分代码
\newcommand{\Snippet}[3]{
\newcommand{#1}{
\srem{#2}{
#3
}
}
}
类似于:
\newcommand{\Snippet}[3]{
% #1 = defPrimitiveRoots this should become cshPrimitiveRoots
% PrimitiveRoots is of course a variable.
\newcommand{#1}{
\srem{#2}{
#3
}
}
% #1 = defPrimitiveRoots this should become beaPrimitiveRoots
\newcommand{#1}{
% I know how to do setup for beamer slide here.
}
}
这是怎么做到的?
答案1
\documentclass{article}
\makeatletter
\newcommand{\SnippetA}[3]{%
\@namedef{csh#1}{\srem{#2}{#3}}%
\@namedef{bea#1}{\srem{#2}{ #3 }}%
}%
\newcommand{\Snippet}[3]{%
% #1 = defPrimitiveRoots this should become cshPrimitiveRoots
% PrimitiveRoots is of course a variable.
\@namedef{csh#1}{\srem{#2}{#3}}%
% #1 = defPrimitiveRoots this should become beaPrimitiveRoots
\@namedef{bea#1}{%
% I know how to do setup for beamer slide here.
}%
}
\makeatother
\providecommand\srem[2]{%
This is the first argument: #1\par
This is the second argument: #2}
\begin{document}
\Snippet{PrimitiveRoots}{Arg one}{Arg two}
\SnippetA{APrimitiveRoots}{Arg one}{Arg two}
\cshPrimitiveRoots
\beaPrimitiveRoots
\cshAPrimitiveRoots
\beaAPrimitiveRoots
\end{document}