# How can I write to file part of text between two flags?

I need to create bi-lingual document, left column in russian and right in english. For this purpose I choose package paracol. But to make it easyer for translator to translate russian text, I want put all russian parts to one group of files (named somedir/text_rus.tex) and all english to another (named somedir/text_eng.tex). To input them I create macro

\long\def\biinput#1{\begin{paracol}{2}\rus\input{#1/text_rus}\switchcolumn%
\eng\input{#1/text_eng}\end{paracol}}


It works, but all two-column images inserts only after the part, but I need them to be inserter where they was mentioned. So, I need some way to synchronise columns and insert image outside paracol environment.

I try such thing:

\newcount\p@rts
\p@rts0
\long\def\writepart#1{
\newwrite\file
\immediate\openout\file=tmp/\number\p@rts.tex
\immediate\write\file{#1}
\immediate\closeout\file
}


The idea is to input english part before russian to create many small files with text between images, after that I simply \input contents of that files after russian text, close paracol and put image.

The problem is how to simplify this. How can I simply put some marker like \syncpoint to english file and when process it write text between consequent markers into another temporary file?

Or maybe I didn't hear about some package that can solve my problem — synchronize text in two columns without need to write this text consequent into one file?

• you mean that you want to be able to switch between the 2 files? Feb 16 '16 at 14:53
• @touhami, yes to take text from second file part by part Feb 16 '16 at 19:24

One thing you can do rather easily is put all the text into macros then merge them together. You might run out of memory rather quickly though.

\documentclass{article}
\usepackage{paracol}
\usepackage{mwe}

\newcounter{merge}
\globalcounter{merge}
\renewcommand{\themerge}{\Alph{merge}}

\newcommand{\merge}[1]% #1 = number of bloxks to merge
{\loop\stepcounter{merge}%
\csname rus\themerge\endcsname
\global\expandafter\let\csname rus\themerge\endcsname=\relax% erase macro
\switchcolumn
\csname eng\themerge\endcsname
\global\expandafter\let\csname rus\themerge\endcsname=\relax% erase macro
\switchcolumn*
\ifnum\value{merge}<#1\repeat
}
%left column to end
\newcommand{\rusA}{\lipsum[1]}
\newcommand{\rusB}{%
\end{paracol}
{\centering\includegraphics{example-image}}
\begin{paracol}{2}
\lipsum[2]}
%right column to end
\newcommand{\engA}{First paragraph}
\newcommand{\engB}{Second paragraph}
%merge macros
\begin{document}
\begin{paracol}{2}
\merge{2}
\end{paracol}
\end{document}

• I don't see the connection between my question and your answer. Can't understand where should I write \begin{image*}... to put wide image between first and second text parts. Feb 16 '16 at 19:37
• I modified my example to add a wide image. Feb 16 '16 at 22:41

Here is a solution. (I use french)

\documentclass{article}
\usepackage{mwe}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{paracol}
\usepackage[frenchb,english]{babel}

\newcount\mt
\newcount\mtt

\def\rus{\selectlanguage{french}}
\def\eng{\selectlanguage{english}}

\def\syncpoint{%
\ifnum\mt=0\else\egroup\fi
\setbox\the\mt=\vbox\bgroup}

\long\def\biinput#1{%
\begin{paracol}{2}
\rus\input{#1/text_rus}%
\eng\input{#1/text_eng}%
\egroup%
\mtt=\mt\relax%
\divide\mtt by 2\relax%
\mt=0\relax%
\loop
\ifnum\mt<\mtt
\unvbox\the\mt%
\par\medskip%
\switchcolumn%
\unvbox\numexpr\mtt+\mt\relax%
\par\medskip%
\switchcolumn*%
\repeat
\end{paracol}}

\begin{document}
\biinput{treza}
\end{document}


text_rus.tex sample:

\syncpoint\textbf{B1}
Généralement, ...
\syncpoint\textbf{B2}
Ce texte a ...
\syncpoint\textbf{B3}
Il circule ...
\syncpoint\textbf{B4}
Nulla facilisi...


text_eng.tex sample

\syncpoint\textbf{A1}
Lorem ipsum dolor...
\syncpoint\textbf{A2}
Class aptent...
\syncpoint\textbf{A3}
Mauris ipsum...
\syncpoint\textbf{A4}
Nulla facilisi...


• This isn't what I want: at syncpoints paracol environment should be ended, after that I put there an image and begin new paracol. Feb 16 '16 at 19:26
• @Eddy_Em you can't adapte my solution? Feb 16 '16 at 19:27
• I tried another variant: tex.stackexchange.com/questions/294238/… I hope, it would be better. Feb 16 '16 at 19:29

Thanks to @egreg! This answer was very usefull. So, I create a MWE that shows an idea.

Contents of file main.tex:

\documentclass[a4paper,12pt]{extarticle}
\usepackage{paracol}
\usepackage[koi8-r]{inputenc}
\usepackage[english,russian]{babel}
\usepackage{expl3}
\makeatletter
\def\@engfigure{Fig.}\def\@rusfigure{Рис.}
\def\@engtable{Table}\def\@rustable{Таблица}
\long\def\bicaption#1#2{%
\refstepcounter\@captype\vskip\abovecaptionskip
{\itshape\protect\select@language{russian}%
{{\bfseries\csname @rus\@captype\endcsname\,\csname%
the\@captype\endcsname:}}~{#1}\par\vspace{8pt}
\protect\select@language{english}%
{{\bfseries\csname @eng\@captype\endcsname\,\csname%
the\@captype\endcsname:}}~{#2}\par}
}
\def\rus{\selectlanguage{russian}}
\def\eng{\selectlanguage{english}}
\ExplSyntaxOn
\seq_new:N \en_seq_items
\int_new:N \en_seq_ctr
\cs_new_protected:Npn \startsync #1 \endsync{
\seq_set_split:Nnn \en_seq_items { \syncpoint } { #1 }
\seq_map_inline:Nn \en_seq_items
{
\int_gincr:N \en_seq_ctr
\tl_gset:cn { en_part \int_to_roman:n { \en_seq_ctr} _tl } { ##1 }
}
}
\def\insrt#1{\tl_use:c { en_part \int_to_roman:n { #1 } _tl }}
\def\paraend{\int_gincr:N \en_seq_ctr\switchcolumn\eng\insrt{\en_seq_ctr}\end{paracol}\rus}
\def\parastart{\begin{paracol}{2}\rus}
\long\def\biinput#1{\global\en_seq_ctr0\eng\input{#1/text_eng}%
\global\en_seq_ctr0\parastart\input{#1/text_rus}\paraend}
\ExplSyntaxOff
\makeatother
\def\arule{\vspace{1em}\hrule\vspace{1em}}
\begin{document}
\biinput{01}
\end{document}


Contents of 01/text_rus.tex:

\section{Какой-то раздел}
Первый абзац
\paraend
\arule
\begin{figure*}[!h]
Here we can paste a wide image
\bicaption{Название изображения на русском языке}{English image name}
\end{figure*}
\arule
\parastart
Второй абзац
\paraend
\arule
Текст шириной на две колонки вне окружения \verb'paracol'.
\arule
\parastart
И заключительный кусок текста


And contents of 01/text_eng.tex:

\startsync
\section{Some section}
First paragraph
\syncpoint
Second paragraph
\syncpoint
Third paragraph
\endsync


Here is result:
(source: pic4a.ru)

The only trouble is need to write \startsync in beginning of every english file and \endsync in its end, because construction like \startsync\input{file}\endsync inside macro don't work.

P.S. another very bad part of this code is usage of awful latex3e syntax. But unfortunately normal syntax would be much more bulky.