配置名稱和電子郵件的自訂命令

配置名稱和電子郵件的自訂命令

我喜歡配置和優化命令,以便獲得以下 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列印,使其與我的 MWE 相同\printprofmail。我的意思是,如果像這樣插入電子郵件,那麼應該顯示帶有超連結的電子郵件地址,如果沒有給出電子郵件,則不應列印任何內容。\prof{Dr. X}[[email protected]]\profemailloc\profemailloc

我想要的輸出 if\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 在命令後產生空格問題,這些問題也應該得到解決。

相關內容