为姓名和电子邮件配置自定义命令

为姓名和电子邮件配置自定义命令

我喜欢配置和优化命令,以便获得以下 MWE 的相同输出,而无需使用单独的命令来插入教授的姓名和电子邮件。

\documentclass{report}
\usepackage{xparse}
\usepackage{hyperref}

\newcommand{\profname}[1]{ \newcommand{\profnameloc}{#1} }
\newcommand{\profemail}[1]{ \newcommand{\profemailloc}{#1} }

\NewDocumentCommand\printprofemail{O{}O{}}{
            \texttt{\href{mailto:\profemailloc}{\profemailloc}}
}

\NewDocumentCommand{\prof}{mO{}}{\newcommand\profloc{\textbf{\href{mailto:#2}{#1}}}}


\begin{document}

\title{Custom Command}
\prof{Dr. X}[[email protected]]
\profname{Dr. X}
\profemail{[email protected]}

\maketitle

The course is taught by \profloc. His name is \profnameloc and his email is \printprofemail.

\end{document}

我的意思是,我想要的输入:

\documentclass{report}

% [necessary packages and commands]

\begin{document}

\title{Custom Command}
\prof{Dr. X}[[email protected]]

\maketitle

The course is taught by \profloc. His name is \profnameloc and his email is \profemailloc.

\end{document}

我想要的输出是这样的:

The course is taught by (Dr. X)[textbf and hyperlinked]. His name is Dr. X and his email is ([email protected])[texttt and hyperlinked].

我想将教授的电子邮件用作命令中的可选参数,\prof这样如果我仅使用命令,它就不会生成空白超链接\prof{Dr. X}。另外,我想优化\profmailloc以打印\printprofmail与我的 MWE 相同的内容。我的意思是,如果像那样插入电子邮件,则应该显示带有超链接的电子邮件地址,如果没有提供电子邮件,则不应打印任何内容。\prof{Dr. X}[[email protected]]\profemailloc\profemailloc

我想要的输出如果\prof{Dr. X}用来代替:\prof{Dr. X}[[email protected]]

The course is taught by (Dr. X)[textbf but not hyperlinked]. His name is Dr. X and his email is .

还应注意,我当前的 MWE 在命令后产生了空白问题,这些问题也应该得到修复。

相关内容