4

I got a file 'month.tex' containing only an integer. I want to set a counter to this integer and tried

\newcounter{billmonth}
\setcounter{billmonth}{\input{month.tex}}

This isn't working as the compiler sais

<to be read again> 
\let 
l.42 \setcounter{billmonth}{\input{month.tex}}

Does anybode have an idea how to deal with this? Thanks!

Why do I have a file containing only this integer? I use a bash script for compiling where you can pass an argument. This argument needs to find its way inside of my latex document and it was the best way i could think of.

synthax
  • 43
  • Related: https://tex.stackexchange.com/questions/321346/how-to-read-a-variable-from-a-file-in-latex, https://tex.stackexchange.com/questions/187878/reading-number-from-file-into-variable-how-to-put-a-number-into-my-document-t –  Oct 28 '17 at 13:19

1 Answers1

9

The readarray package can help, with its \readdef{<filename>}\macro syntax.

\documentclass{article}
\usepackage{filecontents}% this is only to show that it works
\begin{filecontents*}{monthfile}
 3
\end{filecontents*}
\usepackage{readarray}
\readdef{monthfile}\thereadmonth
\newcounter{billmonth}
\setcounter{billmonth}{\thereadmonth}
\begin{document}
\thebillmonth
\end{document}