2

For a critical edition in two languages, my Main.tex file has a loop that:

  1. reads a line from first source file
  2. reads a line from second source file
  3. outputs the lines with the \chunks command
  4. uses \ifeof0 to control \loop by detecting EOF of first source file

A better \loop would check EOF for both source files. However, TeXstudio will not compile \ifeof0 and \ifeof1 in the loop condition. Any advice?


Source files and example code follow.

Please assume source files with these contents.

LeftPageParagraphs.tex:

This is paragraph 1 from LeftPageParagraphs.tex file.

This is paragraph 2 from LeftPageParagraphs.tex file.

RightPageParagraphs.tex:

This is paragraph 1 from RightPageParagraphs.tex file.

This is paragraph 2 from RightPageParagraphs.tex file.

An annotated minimum working example of the problem:

% Test: read lines from files.

\documentclass[openany]{book}

\usepackage{paracol}  % Parallel columns package
\usepackage{forloop}
\usepackage{ifthen}

% The \chunks command outputs two parallel paragraphs 
% to left and right columns on facing pages.
\newcommand\chunks[2]{%
    \begin{leftcolumn*}
        {#1}%
    \end{leftcolumn*}%
    \begin{rightcolumn}
        {#2}%
    \end{rightcolumn}%
    }

\begin{document}

    % Algorithm:
    % Read a line (a paragraph) from input stream 0.
    % Read a line (a paragraph) from input stream 1.
    % Output line to left column on left page.
    % Output line to right column on right page.    
    % Detect end-of-file in input stream 0.

    % PASS with condition: \ifeof0
    % FAIL with condition: { \( \ifeof0 \and \ifeof1 \) }
    % ERROR: Incomplete \ifeof; all text was ignored after line 49.
    
    % Open files in input streams 0 and 1.
    \openin0 = LeftPageParagraphs
    \openin1 = RightPageParagraphs
    
    \begin{paracol}[1]*{2}  
        
        \loop 
        { 
            \read0 to \inputL  
            \read1 to \inputR
  
            \chunks
                {\inputL}
                {\inputR}
        }       
        \( \ifeof0 \and \ifeof1 \) % <-- ERROR
        \repeat

    \end{paracol}
    
    % Close files in input streams 0 and 1.
    \closein0
    \closein1
    
\end{document}
0

1 Answer 1

11

in

\( \ifeof0 \and \ifeof1 \) 

\( and \) are commands for typesetting math, not for evaluating logical expressions

\and is a command used by \maketitle for separating authors

\ifeof0 accesses stream 0 which is reserved by LaTeX as part of \IFFileExists , filecontents and other file related constructs.

replace streams 0 and 1 by two allocated streams

\newread\streamL
\newread\streamR

and combine the tests for example by having a new \if.. command used in the loop

\newif\ifcontinue

\loop
...
\continuetrue
\ifeof\streamL
   \ifeof\streamR
      \continuefalse
   \fi
\fi
\ifcontinue
\repeat

Which will continue the loop until both streams hit eof.

3
  • Perhaps clarify that \(, \) and \and can be used for logical statements only in the first argument of \ifthenelse?
    – Joseph Wright
    Feb 2, 2022 at 10:34
  • 5
    @JosephWright I try to forget about \ifthenelse Feb 2, 2022 at 10:38
  • @JosephWright ah I just now saw the related question on meta Feb 2, 2022 at 17:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .