I need to parse \jobname to extract some metadata (such as the subject of a letter) that is encoded in the filename of the .tex file. The filenames are not restricted to ASCII, but maybe any UTF8 charcater. In particular, I have lots of files with German Umlauts in their name. However, compiling:

% Änderungen.tex


with pdflatex yields:

enter image description here

With lualatex or xelatex the output is fine; however, I would prefer to stay with pdflatex. So how is \jobname actually encoded and how can I transform it?


If you only need to print the jobname, then


is sufficient. The problem is that all characters in the expansion of \jobname have category code 12, so they aren't interpreted in the correct way for printing. With \scantokens we make TeX reread them, but first we need to expand \jobname. The final \noexpand is for avoiding a spurious space at the end.

If instead you want to store the "retokenized" name in a control sequence, then using LaTeX3 is easier:


  \tl_set_rescan:NnV \l_tmpa_tl { } \c_sys_jobname_str
   { \tl_use:N \l_tmpa_tl }
   { \tl_set_eq:NN #1 \l_tmpa_tl }
\cs_generate_variant:Nn \tl_set_rescan:Nnn {NnV}


\UTFjobname X



With only \UTFjobname you print the jobname, with \UTFjobname[\foo] you store the jobname (with the correct category codes) in \foo. The X are there just to show that no space is added when printing.

enter image description here

The terminal will stop at \show\foo with

> \foo=macro:
l.20 \UTFjobname[\foo]\show\foo


As of September 2015, the constant \c_job_name_tl has been removed and changed into \c_sys_jobname_str. The code has been updated accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.