# counter value doubled inside \input if \currfilebase present

Using the package currfile:

\setcounter{foo}{\inputlineno}%
\def\barfile{.aux/\currfilebase\thefoo.bar}%
\def\texfile{.aux/\currfilebase\thefoo.tex}%
% ...
\input{\texfile}


then the counter value is doubled:

! LaTeX Error: File .aux/filename363363.tex' not found.


When \texfile contains only \fname or only \thefoo, I do not see any repetition. Also, using the package fink and \def\fname{\finkfile}, no issues arise.

Minimal working example:

Create a main file containing:

\documentclass{article}
\usepackage{currfile}
\newcounter{counter}
\setcounter{counter}{0}
\begin{document}
\def\texfile{\currfilebase\thecounter.tex}
\input{a_main0.tex}
\input{\texfile}
\end{document}


and another file called a_main0.tex. Typesetting raises the error:

...
(./a_main.aux) (./a_main0.tex)


Clearly, the file a_main0.tex is found by \input, but not when the file name is given using \texfile, because the character "0" gets duplicated.

The statement \def\texfile{\currfilebase\thecounter.tex} is evaluated in the second \input{\texfile} call, but the current input file is a_main0 since \currfilebase switches its content to that name at the moment of \input, so \texfile expands to a_main00.tex.

One possible solution is to use \edef\textfile, i.e. expanded definition, so \currentfilebase is not contained as macro any longer but its value at the time of definition.

a_main.tex

\documentclass{article}
\usepackage{currfile}
\newcounter{counter}
\setcounter{counter}{0}
\begin{document}
\edef\texfile{\currfilebase\thecounter.tex}
\input{a_main0.tex}
\input{\texfile}
\end{document}


a_main0.tex just contains the line

\section{Foo from the file with the 0 suffix}


I neither recommend underscores in graphics files name (even with currfile usage) however (which is not the case here) nor a counter named counter ;-)

• What do you have against underscores in file names? I use them all the time... – clemens Jun 11 '17 at 10:35
• @clemens: in graphics files name was missing ... thanks – user31729 Jun 11 '17 at 10:45
• Thanks, this solves the problem. Indeed, this case is about including LaTeX files, not in any way associated to graphics files. I should note that I have been using underscores in graphics file names for 8 years now, without any problems (not with such a use case though). For example, in a command named \includesvg. I agree about variable naming, the original code has a reasonable name, I chose counter for the MWE. – Ioannis Filippidis Jun 11 '17 at 14:31
• @IoannisFilippidis: You're welcome. Happy TeXing – user31729 Jun 11 '17 at 14:36