I have a project for which I have needed to resort to the morewrites package due to getting a No room for new \write. Up until a few months ago (which was when I last worked on it), this worked quite nicely. But when I tried compiling the document today, it was suddenly uncooperative. After trying to pinpoint the error, I have it narrowed down to this MWE.
\documentclass{article} % Uncomment for error %\usepackage{morewrites} \usepackage{filecontents} \newcounter{globalCounter} \newcounter{hostCounter} \begin{filecontents*}{main.ctr} 123 2 \end{filecontents*} \newcommand*\globalCounterFile{main.ctr} \newwrite\globalCounterFH \immediate\openin\globalCounterFH=\globalCounterFile \immediate\read\globalCounterFH to \globalCounterLine \immediate\read\globalCounterFH to \hostCounterLine \immediate\closein\globalCounterFH \setcounter{globalCounter}{\globalCounterLine} \setcounter{hostCounter}{\hostCounterLine} \stepcounter{globalCounter} \begin{document} This document has been compiled at least~\theglobalCounter~times across~\thehostCounter~hosts so far.\\ \end{document} The MWE works fine as long as \usepackage{morewrites} is commented out, but as soon as the package is loaded, I get the following error when compiling with pdflatex or xelatex:
! Bad number (19). l.15 \immediate\openin\globalCounterFH =\globalCounterFile Since I can't just remove morewrites from my big project, this is a slight bit of an issue.
The code above for reading from main.ctr is very heavily inspired by the counttex package, but I needed to change it slightly for my project to adapt it to my needs. Basically, I need to keep track of two counters instead of one, which are both stored in a file and read line-by-line. Really
I have read that lualatex does not require morewrites, but the main project was written with pdflatex in mind, and trying to compile it with lualatex yields errors which I expect will be trickier to localize and fix than this one.
I am looking for
- Information on why this happens, just out of pure curiosity,
- a solution, if one exists, to solve this problem and to get me back my project without needing to port it to lualatex or get it working without
morewrites(which I already tried last year, rather painfully, resulting in failure). I would prefer to avoid major changes on the project, since I'm basically done with it. But I want to still be able to compile it for archivability purposes and the occasional bugfix in the future.