检测 LaTeX 类名
我正在开发一个 LaTeX 包,它可能需要根据所使用的类以不同的方式执行一些操作。我想知道是否有一种方法可以自动检测或测试文档类。
人们当然可以查找类文件并测试该类定义的特定宏是否存在,但是有没有更聪明的方法呢?我查看了 \ProvidesClass
宏的定义,看不出它是否将类名保存在除 \@currname
之外的任何位置。我相信 \@currname
只是当前正在读取的包或类的名称。
基本上我想
\author{\longauthorname}
在 article
类中执行,但
\author[\shortauthorname]{\longauthorname}
在 beamer
类中执行。
I'm working on a LaTeX package which might need to do some things differently depending on the class that's being used. I'm wondering if there's a way to auto-detect or test the document class.
One could certainly look up the class files and test for the existence of a specific macro defined by that class, but is there a smarter way? I looked at the definition of the \ProvidesClass
macro and can't see if it saves the class name anywhere except \@currname
. I believe \@currname
is just the name of the current package or class being read.
Basically I want to execute
\author{\longauthorname}
in the article
class but
\author[\shortauthorname]{\longauthorname}
in the beamer
class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
完善我的问题后,我将展示我是如何回答的。沿着 dmckee 所说的思路。只需测试功能即可。
\ifcsame
可用于所有 e-TeX 版本,并已记录(以及检查命令是否已定义的其他方法)此处。您无法检查
\author
宏的实际签名(即,它是否需要可选参数?),但您可以检查一些定义为实现可选参数的辅助宏。\beamer@author
是beamer
类中的其中之一。After refining my question I'll show how I answered it. Along the lines of what dmckee was saying. Just test for the functionality.
\ifcsame
is available on all e-TeX builds and is documented (along with other ways to check if a command is defined) here.You can't check for the actual signature of the
\author
macro (i.e., does it take an optional argument?) but you can check for some of the auxiliary macros defined to implement optional arguments.\beamer@author
is one of those in thebeamer
class.恕我直言,您不应该检查您的类(或版本)的名称。
您应该检查功能。
例如,
article
类具有\@titlepagefalse
和book
类具有\@titlepagetrue
。书写
并识别扉页的存在。
IMHO, you should not check the name of your class (or version).
You should check the functionality.
For example, class
article
has\@titlepagefalse
andclass
book
has\@titlepagetrue
.Write
and recognize the presence of title page.
对于加载的文档类有一个简单的测试:
\@ifclassloaded{beamer}{}{}
简短示例:
There is an easy test for the loaded document class:
\@ifclassloaded{beamer}{<true>}{<false>}
Short example: