我想在不同的印刷品中使用作者对象。作者的结构如下:
{
{NameOfFirstAuthor|EmailOfFirstAuthor|CurseOfStudiesOfFirstAuthor|SemesterOfFirstAuthor}
{NameOfFirstAuthor|EmailOfFirstAuthor|CurseOfStudiesOfFirstAuthor|SemesterOfFirstAuthor}
}
它保存在命令中\authors
现在我通过调用以下命令打印这些作者\makeAuthors
:
\newcommand{\makeAuthors}{
\expandafter\printAuthor\authors{}
}
\newcommand{\printAuthor}[1]{
\ifx\relax#1\relax \else
\printedAuthors#1\end \expandafter\printAuthor\fi
}
\def\printedAuthors #1|#2|#3|#4\end{
#1
\varExists{#2}{\\ \href{mailto:#2}{#2} }
\varExists{#3}{\\ #3}
\varExists{#4}{\\ #4. Semester}
}
这样做虽然很好,但是不太灵活。
现在我的问题是:有没有办法可以传递一个命令,\makeAuthors
其中定义了打印的语法。
因此我声明了这个命令:
\def\newWayToPrintAuthors #1|#2|#3|#4\end{
#1
\varExists{#1}{\\ \href{mailto:#2}{#1}}
}
现在我可以调用 \makeAuthors{\newWayToPrintAuthors}。
我更喜欢乳胶溶液,因为我对此有更好的理解,但最终这并不重要,只要它起作用我就很高兴。
这是我迄今为止的尝试:
% Preamble
\documentclass[11pt]{baseClass}
\begin{document}
% Pre Definiton in Package:
\newcommand{\authorPrintTemplate}[4]{}
\newcommand{\makeAuthors}[1]{
\def\commandName#1
\renewcommand{\authorPrintTemplate}{
\commandName{##1}{##2}{##3}{##4}
}
\expandafter\makeSingleAuthor\authors{}
}
\newcommand{\makeSingleAuthor}[1]{
\ifx\relax#1\relax \else
\printedAuthors#1
\end \expandafter\printAuthor\fi
}
\def\buildSingleAuthor #1|#2|#3|#4\end{
\authorPrintTemplate{#1}{#2}{#3}{#4}
}
% What a user of the package needs to do to print something:
\def\authors{
{NameOfFirstAuthor|EmailOfFirstAuthor|CurseOfStudiesOfFirstAuthor|SemesterOfFirstAuthor}
{NameOfSecondAuthor|EmailOfSecondAuthor|CurseOfStudiesOfSecondAuthor|SemesterOfSecondAuthor}
}
\newcommand{\printFullAuthors}[4]{
#1
\varExists{#2}{\\ \href{mailto:#2}{#2} }
\varExists{#3}{\\ #3}
\varExists{#4}{\\ #4. Semester}
\hrule
}
\newcommand{\printAuthorsNames}[4]{
\varExistsElse{#2}{\href{mailto:#2}{#1}}{#1} \\
}
\makeAuthors{printFullAuthors} % I don't care if the user needs to type printFullAuthors or \printFullAuthors
\makeAuthors{printAuthorsNames}
\end{document}
先谢谢了
答案1
像这样
\documentclass[11pt]{article}
\usepackage{hyperref,parskip}
\begin{document}
\newcommand{\makeAuthors}[1]{% don't forget %
\let\authorPrintTemplate#1%
\expandafter\makeSingleAuthor\authors{}%
}
\newcommand{\makeSingleAuthor}[1]{%
\ifx\relax#1\relax \else
\buildSingleAuthor#1\end
\expandafter\makeSingleAuthor
\fi
}
\def\buildSingleAuthor #1|#2|#3|#4\end{%
\authorPrintTemplate{#1}{#2}{#3}{#4}%
}
% What a user of the package needs to do to print something:
\def\authors{
{NameOfFirstAuthor|EmailOfFirstAuthor|CurseOfStudiesOfFirstAuthor|SemesterOfFirstAuthor}
{NameOfSecondAuthor|EmailOfSecondAuthor|CurseOfStudiesOfSecondAuthor|SemesterOfSecondAuthor}
}
\newcommand{\printFullAuthors}[4]{%
#1
\varExists{#2}{\\ \href{mailto:#2}{#2} }%
\varExists{#3}{\\ #3}5
\varExists{#4}{\\ #4. Semester}\par
\hrule
}
\newcommand{\printAuthorsNames}[4]{%
\varExistsElse{#2}{\href{mailto:#2}{#1}}{#1}\par
}
\def\varExists#1#2{#2}%?
\def\varExistsElse#1#2{#1}%?
\makeAuthors{\printFullAuthors} % I don't care if the user needs to type printFullAuthors or \printFullAuthors
\bigskip *** \bigskip
\makeAuthors{\printAuthorsNames}
\end{document}