Luatex – Solving Problems with Currfile in Luatex

currfileluatex

Here is my MWE:


\documentclass[ngerman,german,14pt,twoside,openany]{scrbook}
\usepackage[left=2.5cm,right=2.5cm,top=2cm,bottom=2.5cm]{geometry}
\usepackage[ngerman]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{currfile} 

\begin{document}


\ifcurrfiledir{folder1/folder2/Jungs}{Lieber}{Liebe}
\end{document}

I am struggling with the following problem:
In german language you talk to boy with the word "Lieber…" and you talk to a girl with the word "Liebe…" (for our english speaking friends: this means "Dear…". Now I would like to automate these words in a way that if the document is in the folder "folder1/folder2/Jungs" (Jungs means boy) then the word "Lieber" should be inserted and for the rest (i.e. the girls) the word "Liebe" should be used. For this purpose I tried the "currfile" package by Martin Scharrer with the code detailed above. But this doesn´t work since in both cases Lualatex returns "Liebe". Can anyone help me please?

Best Answer

If you want to run LuaLaTeX from within the directory, you cannot test with \ifcurrfiledir, because the \currfiledir is relative to the current working directory. But you can (always) do a test with \currfileabspath, e.g.:

\documentclass[ngerman,german,fontsize=14pt,openany]{scrbook}
\usepackage[left=2.5cm,right=2.5cm,top=2cm,bottom=2.5cm]{geometry}
\usepackage[main=ngerman]{babel}
\usepackage[abspath]{currfile} 

\ExplSyntaxOn
\NewDocumentCommand \JungsMaedelsSonstige { m m m }
  {
    \str_if_in:NnTF
      \currfileabspath
      { /Jungs/ }
      { #1 }
      {
        \str_if_in:NnTF
          \currfileabspath
          { /Maedels/ }
          { #2 }
          { #3 }
      }
  }
\ExplSyntaxOff

\begin{document}

Dies ist Datei \currfileabspath{} für \JungsMaedelsSonstige{Jungs}{Mädels}{Sonstige}.

\end{document}

Note: Because of option abspath you have to run LaTeX with option -recorder. If the file above is named jungsornot.tex you would, e.g., have to run pdflatex -recorder jungsornot.tex instead of pdflatex jungsornot.tex.

Related Question