7

My file is named 'cv3.01.tex'. I want to extract the '3.01' part and use it in the footer of the document, i.e. 'Rev 3.01'.

I found Parsing file name into document, but it does not work for my filename structure.

Here is my code based on the above:

\documentclass{article}

\makeatletter
\newcommand{\filenameparse}[1]{\expandafter\filename@parse@#1\@nil}
\def\filename@parse@#1\@nil{%
  \gdef\fileRev{#1}% first part
}
\makeatother

\begin{document}
    \filenameparse{\jobname}

    Rev. \fileRev
\end{document}

Of course, \fileRev is 'cv3.01' because I don't know how to parse that out. Using this in the above:

\def\filename@parse@{cv#1}@\nil{%

does not work.

2
  • 2
    It is probably wiser for many reasons to have your CV under version control (everyone seems to like git nowadays), and then access the version that way (say with gitinfo2).
    – jon
    Oct 10, 2015 at 17:30
  • Try \def\filename@parse@ cv#1\@nil{% Oct 10, 2015 at 17:53

2 Answers 2

5

It's the usual problem that \jobname expands to characters with category code 12; but you just have to gobble two tokens.

\documentclass{article}

\makeatletter
\def\getcv@revision#1#2#3\@nil{#3}
\edef\revision{\expandafter\getcv@revision\jobname\@nil}
\makeatother

\begin{document}

This document is Rev~\revision.

\end{document}

enter image description here

A customizable solution allowing for any prefix:

\documentclass{article}

\makeatletter
\edef\revision@prefix{\detokenize{%
  % customize based on the file name structure
  cv% <---- change the characters before %
}}
\expandafter\def\expandafter\revision@get\revision@prefix#1\@nil{#1}
\edef\revision{\expandafter\revision@get\jobname\@nil}
\makeatother

\begin{document}

This document is Rev~\revision.

\end{document}

Detokenizing is necessary because the characters produced by \jobname have category code 12.

3

Not very elegant:

\documentclass[10pt]{article}

\def\stripfirst#1#2{#2}
\edef\filerev{\expandafter\stripfirst\jobname}%remove c
\edef\filerev{Rev \expandafter\stripfirst\filerev}%remove v

\begin{document}
\filerev
\end{document}

You must log in to answer this question.

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