2

Yesterday I asked a question about the "currfile" package I wanted to use for writing a document about several pupils in my school and @cabuha provided a very nice answer for this problem: Problem with ifthenelse (all credits to @cabuha). While working on the document a new idea came to my mind: I would like to build up a "database" of approx. 200 pupils for the next semester painting pictures which have to be published in a catalogue. So I tried to modify the solution of @cabuha in the following way:

%https://tex.stackexchange.com/questions/720935/problem-with-ifthenelse

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

%\usepackage{currfile}
\usepackage[abspath]{currfile}

\ExplSyntaxOn
%\newcommand{\textforpicture}[1]% could be used, but using
\NewDocumentCommand \picturename { m } % is usual for defining a user command in l3 context.
  {
    \str_case:nnF { #1 }
      {
        {George} {Title~1}
        {James} {Title~2}
        {Jenny} {Title~3}
        %{\currfilebase} {Title~4}
      }
      {}
  }%
\ExplSyntaxOff  


\ExplSyntaxOn
%\newcommand{\textforpicture}[1]% could be used, but using
\NewDocumentCommand \picturedescription { m } % is usual for defining a user command in l3 context.
  {
    \str_case:nnF { #1 }
      {
        {George} {Some~people}
        {James} {Some~more~people}
        {Jenny} {Even~more~people}
        %{\currfilebase} { Today~is~a~sunny~day! }
      }
      {}
  }%
\ExplSyntaxOff  



\begin{document}

George:\\ The title of you picture runs: \picturename{George}.\\ Your picture shows: \picturedescription{George}\\

James:\\ The title of you picture runs: \picturename{James}.\\ Your picture shows: \picturedescription{James}\\

Jenny:\\ The title of you picture runs: \picturename{Jenny}.\\ Your picture shows: \picturedescription{Jenny}\\

The name of this file is: \currfilebase.\\

Dear \currfilebase: The name of your picture is \picturename{\currfilebase}. And here is what you have to say about your picture: \picturedescription{\currfilebase}. Very nice!

\end{document} 

The name of the file would be name of the pupil, e.g "George". If I compile the document "George" the output doesn´t work as expected: the last sentence runs "The name of your picture is . And here is what you have to say about your picture: "As long as I provide an actual name, i.e. "Geroge", "James" or "Jenny" the output is as expeted. But when I replace the name by the command "\currfilebase" it doesn´t work any longer, i.e. in my example provided here the last sentence runs "Dear George: The name of your picture is (NOTHING IN HERE) . And here is what you have to say about your picture: (NOTHING IN HERE) . Very nice". To my knowledge the command "\currfile" returns the actual name of the file. So why does this not work in my example? Any help is greatly appreciated!

4
  • There is not “(NOTHING IN HERE)” in the output of your example.
    – cabohah
    Commented Jun 20 at 9:59
  • @cabohah: I am by far not an expert like you, so sorry if some questions are "crazy". Following your comment I changed "\str_case:nnF { #1 }" into "\str_case:enF { #1 }" and everything works as expected. Thanks again for your help! Have a nice day! Best regards
    – mario1000
    Commented Jun 20 at 10:00
  • 1
    IMHO none of the two questions is about package currfile, but all are about comparing strings. So I've changed the title and the tags at least of this question.
    – cabohah
    Commented Jun 20 at 10:31
  • @cabohah: that seems to be a more valid solution, thanks!
    – mario1000
    Commented Jun 20 at 10:58

1 Answer 1

3

I don't understand, why you are talking about picture files. \currfilebase does not handle any picture file names, but the basename of the current file. So the result of \picturedescription{\currfilebase} depends on the basename of your example TeX file.

But maybe your main problem is: If you use a macro inside the argument of \picturename and the macro should be expanded before the strings are compared, you have to use, e.g., \str_case:enF instead of \str_case:nnF. In your current example the string \currbasename is compared with George etc. not the expansion of \currbasename. See “The LaTeX3 interfaces”, which I've already linked in my answer to the original question, for more information about the argument specifiers e, n, N, v etc.

Assume, the following file is named George.tex:

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

%\usepackage{currfile}
\usepackage[abspath]{currfile}

\ExplSyntaxOn
%\newcommand{\textforpicture}[1]% could be used, but using
\NewDocumentCommand \picturename { m } % is usual for defining a user command in l3 context.
  {
    \str_case:enF { #1 }
      {
        {George} {Title~1}
        {James} {Title~2}
        {Jenny} {Title~3}
      }
      {unknown~name~#1}
  }%
\ExplSyntaxOff  


\ExplSyntaxOn
%\newcommand{\textforpicture}[1]% could be used, but using
\NewDocumentCommand \picturedescription { m } % is usual for defining a user command in l3 context.
  {
    \str_case:enF { #1 }
      {
        {George} {Some~people}
        {James} {Some~more~people}
        {Jenny} {Even~more~people}
        %{\currfilebase} { Today~is~a~sunny~day! }
      }
      {unknown~name~#1}
  }%
\ExplSyntaxOff  


\begin{document}

George:\\ The title of you picture runs: \picturename{George}.\\ Your picture shows: \picturedescription{George}\\

James:\\ The title of you picture runs: \picturename{James}.\\ Your picture shows: \picturedescription{James}\\

Jenny:\\ The title of you picture runs: \picturename{Jenny}.\\ Your picture shows: \picturedescription{Jenny}\\

The name of this file is: \currfilebase.\\

Dear \currfilebase: The name of your picture is \picturename{\currfilebase}. And here is what you have to say about your picture: \picturedescription{\currfilebase}. Very nice!

\end{document} 

then the result would be:

result for Goerge.tex

But if the file is named test.tex, the result would be:

result for test.tex

Just some additional notes:

  • In this examples you don't really need package currfile. You could just use \jobname instead of \currfilebase.

  • And IMHO you should not use \\ inside justified text, also not to fake a paragraph or add a vertical distance. IMHO it is nicer to use something like:

\documentclass[ngerman,14pt,twoside,openany]{scrbook}
\usepackage[margin=2.5cm]{geometry}% Not really recommended, but you want it.
\usepackage{babel}

\usepackage[abspath]{currfile}

\ExplSyntaxOn
\NewDocumentCommand \picturename { m }
  {
    \str_case:enF { #1 }
      {
        {George} {Title~1}
        {James} {Title~2}
        {Jenny} {Title~3}
      }
      {unknown~name~#1}
  }%

\NewDocumentCommand \picturedescription { m }
  {
    \str_case:enF { #1 }
      {
        {George} {Some~people}
        {James} {Some~more~people}
        {Jenny} {Even~more~people}
      }
      {unknown~name~#1}
  }%
\ExplSyntaxOff  


\begin{document}

\raggedright
\minisec{George:}
The title of you picture runs: \picturename{George}.

Your picture shows: \picturedescription{George}.

\minisec{James:}
The title of you picture runs: \picturename{James}.

Your picture shows: \picturedescription{James}.

\minisec{Jenny:}

The title of you picture runs: \picturename{Jenny}.

Your picture shows: \picturedescription{Jenny}.

\minisec{And know using \texttt{\string\currfilebase}:}
The name of this file is: \currfilebase.

Dear \currfilebase: The name of your picture is \picturename{\jobname}. And
here is what you have to say about your picture:
\picturedescription{\currfilebase}.

Very nice!

\end{document}

enter image description here

For more alternatives see also KOMA-Script option parskip and commands like \bigskip, \medskip etc.

You must log in to answer this question.

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