Is there a way to programmatically determine which document class is in effect?
I'd like to be able to write conditional macros that behave differently depending on which document class is currently being used.
|
Is there a way to programmatically determine which document class is in effect? I'd like to be able to write conditional macros that behave differently depending on which document class is currently being used. |
||||
|
|
|
You want the LaTeX kernel function
|
|||||
|
|
If you want to differentiate between KOMA-Script-classes (
|
||||
|
|
|
If your package executes
and use like:
|
||||
|
|
|
Actually a class is loaded with the same internal macros like packages (both are officially "files with options") and LaTeX doesn't store the class file name in a specific macro. So you can't directly test which class was used, only test whether a specific class was used or not using Also keep in mind that a class can be based on another class by loading it with |
|||||
|
|
I came up with the following scenario, which isn't advisable in practice but which is of theoretical interest. David Carlisle's solution still works in this case but doesn't tell the complete story.
David Carlisle's solution
gives 'article' as the class, while in reality it may be 'testclass' that the user needs. So my approach is to find all the classes in effect, upon which further action can be taken:
This can be called simply as
|
||||
|
|
|
Expanding on Ahmed's idea, here's some code with LaTeX3:
The final lines show how the information can be used, by testing whether a class name appears in the sequence. One can similarly test what packages have been loaded so far. Here's a more complete code, where three sequences are built where classes, packages and other files are stored, respectively:
The example uses |
||||
|
|