
我嘗試為作者和標題命令實現元級別,因為大多數樣式文件希望它們有點不同,並且我希望能夠輕鬆更改樣式文件。
長話短說amsart
,當我將巨集插入到\title{}
.它不會引發錯誤,但不會將標題大寫。然而,它仍將以粗體排版。
所以既沒有沒有效果,也沒有全部效果。我也嘗試放置\expandafter
在我能想到的所有地方,但顯然我並不真正理解這個命令。
\documentclass[a4paper,reqno]{amsart}
\usepackage[utf8]{inputenc}
\begin{document}
\newtoks\mytitleA
\mytitleA={This is a title}
\newcommand{\mytitle}{This is a title}
\newcommand{\myauthor}{This is me}
% toggle the following commands to see that only the last version
% produceses the correct layout
%\title{\the\mytitleA}
%\title{\mytitle}
\title{This is a title}
% for the author I cannot spot a difference
\author{\myauthor}
\author{This is me}
\maketitle
\end{document}
其他樣式檔案(如)article
似乎不會以不同的方式排版標題,如果它嵌套在巨集中,至少我無法區分。因此, oramsart
的實作可能有問題。\title{}
\maketitle
有沒有辦法解決這個問題或至少讓巢狀巨集起作用?
答案1
你忘了一個做工作,即
\expandafter\title\expandafter{\the\mytitleA}
當然,\the
前面的任何避免\mytitleA
都行不通,因為\the
為了傳遞\toks
暫存器的內容這是必要的。
有什麼問題?預設amsart
只使用\uppercase
(不應該,但這是另一個問題)。
您可以透過在完成其工作之前載入textcase
強制amsart
使用\MakeTextUppercase
完整(受保護的)擴充功能來避免此問題。\uppercase
帶\toks
寄存器
\documentclass[a4paper,reqno]{amsart}
\usepackage{textcase}
\newtoks\mytitleA
\mytitleA={This is a title}
\newcommand{\myauthor}{This is me}
\begin{document}
\title{\the\mytitleA}
\author{\myauthor}
\maketitle
\end{document}
用指令
\documentclass[a4paper,reqno]{amsart}
\usepackage{textcase}
\newcommand{\mytitle}{This is a title}
\newcommand{\myauthor}{This is me}
\begin{document}
\title{\mytitle}
\author{\myauthor}
\maketitle
\end{document}