Skip to main content
More complete example
Source Link
egreg
  • 1.2m
  • 147
  • 2.8k
  • 4.5k

Expanding on Ahmed's idea, here's some code with LaTeX3:

\RequirePackage{expl3} \ExplSyntaxOn \seq_new:N \l_pclist_classes_seq \clist_map_inline:cn { @filelist } { \tl_if_in:nnT { #1 } { .cls } { \tl_set:Nn \l_tmpa_tl { #1 } \tl_remove_once:Nn \l_tmpa_tl { .cls } \seq_put_right:NV \l_pclist_classes_seq \l_tmpa_tl } } \seq_if_in:NnTF \l_pclist_classes_seq { article } { \msg_term:x { The~class~`article'~is~loaded } } { \msg_term:x { The~class~`article'~is~NOT~loaded } } \ExplSyntaxOff 

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:

\documentclass{ltxdoc} \RequirePackage{expl3} \ExplSyntaxOn \seq_new:N \l_pclist_classes_seq \seq_new:N \l_pclist_packages_seq \seq_new:N \l_pclist_other_seq \clist_map_inline:cn { @filelist } { \tl_if_in:nnTF { #1 } { .cls } { \tl_set:Nn \l_tmpa_tl { #1 } \tl_remove_once:Nn \l_tmpa_tl { .cls } \seq_put_right:NV \l_pclist_classes_seq \l_tmpa_tl } { \tl_if_in:nnTF { #1 } { .sty } { \tl_set:Nn \l_tmpa_tl { #1 } \tl_remove_once:Nn \l_tmpa_tl { .sty } \seq_put_right:NV \l_pclist_packages_seq \l_tmpa_tl } { \seq_put_right:Nn \l_pclist_other_seq { #1 } } } } \seq_if_in:NnTF \l_pclist_classes_seq { article } { \msg_term:x { The~class~`article'~is~loaded } } { \msg_term:x { The~class~`article'~is~NOT~loaded } } \seq_show:N \l_pclist_classes_seq \seq_show:N \l_pclist_packages_seq \seq_show:N \l_pclist_other_seq \ExplSyntaxOff 

The example uses ltxdoc as base class in order to show that it's item 0 in the "classes" sequence.

Expanding on Ahmed's idea, here's some code with LaTeX3:

\RequirePackage{expl3} \ExplSyntaxOn \seq_new:N \l_pclist_classes_seq \clist_map_inline:cn { @filelist } { \tl_if_in:nnT { #1 } { .cls } { \tl_set:Nn \l_tmpa_tl { #1 } \tl_remove_once:Nn \l_tmpa_tl { .cls } \seq_put_right:NV \l_pclist_classes_seq \l_tmpa_tl } } \seq_if_in:NnTF \l_pclist_classes_seq { article } { \msg_term:x { The~class~`article'~is~loaded } } { \msg_term:x { The~class~`article'~is~NOT~loaded } } \ExplSyntaxOff 

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.

Expanding on Ahmed's idea, here's some code with LaTeX3:

\RequirePackage{expl3} \ExplSyntaxOn \seq_new:N \l_pclist_classes_seq \clist_map_inline:cn { @filelist } { \tl_if_in:nnT { #1 } { .cls } { \tl_set:Nn \l_tmpa_tl { #1 } \tl_remove_once:Nn \l_tmpa_tl { .cls } \seq_put_right:NV \l_pclist_classes_seq \l_tmpa_tl } } \seq_if_in:NnTF \l_pclist_classes_seq { article } { \msg_term:x { The~class~`article'~is~loaded } } { \msg_term:x { The~class~`article'~is~NOT~loaded } } \ExplSyntaxOff 

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:

\documentclass{ltxdoc} \RequirePackage{expl3} \ExplSyntaxOn \seq_new:N \l_pclist_classes_seq \seq_new:N \l_pclist_packages_seq \seq_new:N \l_pclist_other_seq \clist_map_inline:cn { @filelist } { \tl_if_in:nnTF { #1 } { .cls } { \tl_set:Nn \l_tmpa_tl { #1 } \tl_remove_once:Nn \l_tmpa_tl { .cls } \seq_put_right:NV \l_pclist_classes_seq \l_tmpa_tl } { \tl_if_in:nnTF { #1 } { .sty } { \tl_set:Nn \l_tmpa_tl { #1 } \tl_remove_once:Nn \l_tmpa_tl { .sty } \seq_put_right:NV \l_pclist_packages_seq \l_tmpa_tl } { \seq_put_right:Nn \l_pclist_other_seq { #1 } } } } \seq_if_in:NnTF \l_pclist_classes_seq { article } { \msg_term:x { The~class~`article'~is~loaded } } { \msg_term:x { The~class~`article'~is~NOT~loaded } } \seq_show:N \l_pclist_classes_seq \seq_show:N \l_pclist_packages_seq \seq_show:N \l_pclist_other_seq \ExplSyntaxOff 

The example uses ltxdoc as base class in order to show that it's item 0 in the "classes" sequence.

Source Link
egreg
  • 1.2m
  • 147
  • 2.8k
  • 4.5k

Expanding on Ahmed's idea, here's some code with LaTeX3:

\RequirePackage{expl3} \ExplSyntaxOn \seq_new:N \l_pclist_classes_seq \clist_map_inline:cn { @filelist } { \tl_if_in:nnT { #1 } { .cls } { \tl_set:Nn \l_tmpa_tl { #1 } \tl_remove_once:Nn \l_tmpa_tl { .cls } \seq_put_right:NV \l_pclist_classes_seq \l_tmpa_tl } } \seq_if_in:NnTF \l_pclist_classes_seq { article } { \msg_term:x { The~class~`article'~is~loaded } } { \msg_term:x { The~class~`article'~is~NOT~loaded } } \ExplSyntaxOff 

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.