For the purpose of learning the new expl3 syntax I have decided to rewrite my varsfromjobname package that separates the jobname into diffent tokens. I am struggling however with the new syntax. So far I have understood that I need to define a target variable of type sequence, which takes the individual strings as well as use the \seq_set_split function to do the split.


\seq_new:N \l_vfjn_seq
\seq_set_split:Nnn \l_vfjn_seq {-} {\jobname}




But how can I proceed from there? I read about an l3seq package, but \usepackage{l3seq} resulted in an error that the package could not be found.


3 Answers 3


You don't need any packages for this since xparse and expl3 are part of the kernel. So you can use these directly. This also includes l3seq. The full interface is documented in texdoc interface3.

After splitting, you can access individual parts of the sequence using \seq_item:Nn:


\seq_new:N \l_vfjn_seq % Keep the _new: outside of the command.
\NewDocumentCommand \vfjn {} {
  \seq_set_split:NnV \l_vfjn_seq {-} \c_sys_jobname_str % :NnV instead of :Nnn to ensure that the value of \jobname gets split nd not the token list containing only \jobname itself.
\NewExpandableDocumentCommand \vfjnGetComponent {m} {
  \seq_item:Nn \l_vfjn_seq {#1} % You can access the elements with \seq_item:Nn


The third part of the current jobname is \vfjnGetComponent{3}.


Compiled with lualatex -jobname first-second-third-final filename this results in

enter image description here


That's quite easy:

  \seq_item:Nn \c_varsfromjobname_main_seq { #1 }

\seq_new:N \g_varsfromjobname_main_seq
\seq_gset_split:NnV \g_varsfromjobname_main_seq { - } \c_sys_jobname_str

Then you can extract expandably any part you want. You can also define

  \getfromjobname { 1 }

and so on.

It would be a bit more difficult to expandably access the current file name parts, because this requires maintaining a stack of the split file names and some heavy surgery on filehook.

The -----...- technique would work very similarly.

  • @MarcelKrüger Oversight fixed. One might also argue that (some of) the features of filehook should be incorporated in the kernel.
    – egreg
    May 22, 2022 at 21:06

That is quite easy with only TeX primitives too:

\def\getfromjobnameA #1-#2-#3-#4-#5-#6-#7-#8\end#9{%
   \ifcase #9\or#1\or#2\or#3\or#4\or#5\or#6\or#7\else
       \getfromjobnameA#8--------\end{\numexpr #9-7\relax}\fi

% if \jobname returns aaa-bbb-ccc then
\getfromjobname2 returns bbb
% if \jobname returns 1-2-3-4-5-6-7-8-9-10-11-12-13-14-15 then
\getfromjobname{13} returns 13

The advantage of this solution is that your macros is independent of LaTeX and they are usable in other formats too. Moreower, it is independent of expl3 macros.

The recursive call of \getfromjobnameA allows to get arbitrary part of the \jobname if there are more parts in it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .