1

I use one .tex file to create multiple CV depending on the \jobname. For that I use the ifthen package and for each type of CV I create a Boolean value that I use to conditionally include some text. Now I want to make my tex file multilingual (french and english) so the \jobname will contain two information the job itself and the language name. For that I want to use regex. But I don't succeed to perform a regex in \jobname? So can you help me to apply a regex on a jobname like <jobname>-<lang So currently I have this code

\usepackage{ifthen}
\usepackage[main=french,english]{babel}
----
\ifthenelse{\equal{\detokenize{ingmod}}{\jobname}}{\DEVtrue}{}
----

And I use the \DEVtrue (and the other Boolean for conditional compila now I want to define the argument to pass to babel using conditional compilation. with the lang part of the \jobname. Of course, I use a Makefile to wrap the latexmk commands for each compilation.

3
  • 1
    do you need a regex or just split on - ? Feb 8, 2022 at 14:50
  • Welcome! Can you please make a small example explaining in more detail what you want to achieve?
    – egreg
    Feb 8, 2022 at 15:05
  • I added more explanation in my post.
    – mveril
    Feb 8, 2022 at 16:23

1 Answer 1

1

If I understand your question, you have main file named foo-bar.tex and you need to check if the first part of the job name is foo. You can do this by following macros:

\def\readjobname #1-#2\end{\def\name{#1}\def\lang{#2}}
\def\isname #1\iftrue{\edef\tmp{\detokenize{#1}}\ifx\tmp\name}

\expandafter\readjobname \jobname\end  % reading both parts of the job name

\isname ingmod\iftrue Name is ingmod\else Name isn't ingmod\fi

\isname foo\iftrue Name is foo\else Name isn't foo\fi

\bye

The example above assumes that the job name must be in the form foo-bar. If the hyphen - is missing here, then it fails. But you can do the macro more robust:

\def\readjobname #1-#2\end{\def\name{#1}\def\lang{#2}}
\def\isname #1\iftrue{\edef\tmp{\detokenize{#1}}\ifx\tmp\name}
\def\isindash #1-#2\iffalse{\ifx\relax#2\relax}

\expandafter\isindash \jobname-\iffalse  % reading job name
   \edef\name{\jobname}\def\lang{}
\else
   \expandafter\readjobname \jobname\end
\fi

\isname ingmod\iftrue Name is ingmod\else Name isn't ingmod\fi

\isname foo\iftrue Name is foo\else Name isn't foo\fi

\bye

Now, if there isn't hyphen character then name is full jobname and \lang is empty.

2
  • Thank you very much! It works fine even though I don't understand all the code. I don't know the syntax of the \def command. I'm used to using \newcommand and \newdocumentcommand.
    – mveril
    Feb 9, 2022 at 9:19
  • @mveril \def is TeX priitive command for defining macros. LaTeX is macro package. \newcommand is a LaTeX macro which checks if the defined control sequence is defined already and if not then the macro processes \def internally.
    – wipet
    Feb 9, 2022 at 20:02

You must log in to answer this question.

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