2

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?

3
  • 2
    Unrelated but don't do \usepackage[utf8x]{inputenc} (utf8x has not been recommended for years, and in current releases it is defined to do nothing other than give a warning that it should not be used) Commented Nov 27, 2023 at 11:25
  • 2
    You don't say how you are running LaTeX, but the most obvious would be that you are already in folder1/folder2/Jungs, so there is no relative folder.
    – Joseph Wright
    Commented Nov 27, 2023 at 11:32
  • Off-topic: Option 14pt for scrbook is obsolete. You should use fontsize=14pt instead as reported in the log file and shown in my answer. And if you have several options in the option list of \documentclass but only the main language as option for babel, it is recommended to use main=… when loading babel to avoid warnings. See again the warning in the log file of your example.
    – cabohah
    Commented Nov 27, 2023 at 12:07

1 Answer 1

4

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.

2
  • Thank you for your help. Just another (maybe silly) question: I am using WinEdt (under Windows) as my editor. How do I start "pdflatex -recorder" from the editor or do I have to start from command line?
    – mario1000
    Commented Nov 27, 2023 at 12:32
  • @mario1000 I'm not using WinEdt, but you should be able to add -recorder analogous to enable shell-escape with WinEdt. If not, please ask another question.
    – cabohah
    Commented Nov 27, 2023 at 12:39

You must log in to answer this question.

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