0

So i am reading a number from a file and i'd like to increase it and write it back to the file each time i compile the .tex-file. The problem is that the number is not increased by +1 as i scripted it, instead it is raised by 4 when i'm reading the file. E.g. file contains 1, reading the file and making an output gives 5 (i have no clue why?), adding 1 and writing back works fine. The file contains 6, reading the file again gives 10. Why is reading a number from a file increasing it by 4?

\documentclass{article}
\usepackage[nomessages]{fp}

\begin{document}

\def\chopline#1\\{  
    \def\Build{#1} 
}

%---read file--------------
\newread\quelle
\openin\quelle=number.dat
\read\quelle to \zeile 
\expandafter\chopline\zeile\\ 
read: \Build 
\closein\quelle
%--EOF-----------------------------------

%--increase-----------------------
\FPeval{\build}{clip(\Build + 1)}
new number: \build 
%--EOI---------------------

%--write file-----------
\newwrite\outfile 
\immediate\openout\outfile=number.dat % open file
 \immediate\write\outfile{\build} 
\immediate\closeout\outfile % close file
%--EOF------------------------------------

\end{document}

File number.dat must exist and has to contain 1 to work properly otherwise u have to enter \zeile=1.

Thank u in advance!

Mago
  • 67
  • 8
  • Works as expected for me (the number is increased by +1), I am using `pdflatex` to compile. How do you compile? Are you using an IDE? – sergej Aug 28 '15 at 17:39
  • I am using pdflatex aswell, but i think i've found my failure. Because i have a bibliography and an index of abbreviation i have to compile more than one time and because i am compiling 4 times it increases the number by 4. It crossed my mind when i read your answer. Thanks anyways! – Mago Aug 31 '15 at 06:45

0 Answers0