My script needs to read a command from one aux file (testFileWriteReadExecute.yposIN.txt), then execute that same command which is a actually a call to a write macro which writes another command to a second file (testFileWriteReadExecute.yposOUT.txt).
Currently it produces the command in the PDF output instead of executing it. At some stage I had something similar working halfway, but have messed it up since, unfortunately.
testFileWriteReadExecute.yposin.txt looks like this:
\writeVerse{A}{1}{F}\comment{30580738}\endcomment
\writeVerse{A}{1}{L}\comment{29138946}\endcomment
\writeVerse{A}{2}{F}\comment{29138946}\endcomment
\writeVerse{A}{2}{L}\comment{27566082}\endcomment
\writeVerse{A}{3}{F}\comment{27566082}\endcomment
\writeVerse{A}{3}{L}\comment{25993218}\endcomment
MWE:
\documentclass[pagesize=pdftex, fontsize=10]{scrbook}
\usepackage[paperwidth=11.2cm, paperheight=17.4cm, top=1cm,bottom=1cm, left=1cm, right=1cm]{geometry}
\usepackage{fontspec}
\AtBeginDocument{%
\newwrite\yposoutputfile%
\openout\yposoutputfile=\jobname.yposout.txt%
}
\AtEndDocument{%
\closeout\yposoutputfile%
}
\newcommand\writeVerse[3][]{%
\writelines{#1}{#2}{#3}%
}
% Write the position to file.
\def\writelines#1#2#3{%
\pdfsavepos%
\write\yposoutputfile{%
\string\writeVerse%
\string{#1\string}%
\string{#2\string}%
\string{#3\string}%
\string\comment\string{\the\pdflastypos\string}\string\endcomment%
}%
}
% Open the file to read the commands.
\def\fromFile{
\newread\yposinputfile%
\openin\yposinputfile=\jobname.yposin.txt%
\readline\yposinputfile to \fromFileLine%
\closein\yposinputfile%
\fromFileLine
}
\begin{document}
\fromFile %\writeVerse{A}{1}{F}
LIBRO de la generación de Jesucristo, hijo de David, hijo de Abraham. \fromFile %\writeVerse{A}{1}{L}
\writeVerse{A}{2}{F} \textbf{2}~Abraham engendró á Isaac: é Isaac engendró á Jacob: y Jacob engendró á Judas y á sus hermanos:\writeVerse{A}{2}{L}
\writeVerse{A}{3}{F} \textbf{3}~Y Judas engendró de Thamar á Phares y á Zara: y Phares engendró á Esrom: y Esrom engendró á Aram:\writeVerse{A}{3}{L}
\end{document}
EDIT
The basic concept of what I want is simple.
- The
XeLaTeX
script grabs a line from the one text file which happens to be aTeX
command, i.e.\writeVerse{A}{1}{F}
- It places in a particular place of the document this command, where this command gets executed/expanded instead of printed.
- The command is a call to a macro which in turn writes to another file.
EDIT 2:
Since the closest answer is this one by egreg I'll accept it, although it does not answer the fundamentals of my question. It does seem that this is a limitation in TeX.
\fromFile
command always reads the first line, because it opens and closes the file each time. But the main problem is that it can't be read, because it has been also opened for writing in it, so it's empty when\fromFile
is found.\jobname.yposIN.txt
and a\jobname.yposOUT.txt
. Did I miss something there?tex
script. Both exists with contents after thexelatex
run, although the output is shorting the first two lines, due to the write command not executing.\th@mbs@verview
from the thumbs package: "The internal command\th@mbs@verview
reads a line from file\jobname.tmb
and executes the content of that line - if that line has not been processed yet, in which case it is just ignored (see\@unused
)."