同步双语页面上的文本

同步双语页面上的文本

这是一个相当技术性的问题。其中的本质是 XeLaTeX 如何处理分页。

我需要制作一本双语书。左侧页面使用一种语言,右侧页面使用另一种语言来涵盖相同的文本。

有几点需要牢记:

  • 正在制作的书是《圣经》,所以它是一本非常大的文本,因此尽可能多的工作应该实现自动化。
  • 每组页面都需要以两种语言的相同诗句结束。
  • 以下 MWE 中包含的所有包实际上都被最终产品中的其他功能所使用。

因此,考虑到所有这些,问题是:XeLaTeX 是否有能力找出我的文本在页面上使用了多少。或者哪个是页面上最后Section使用Subsection的。这样它就可以用于第二种语言,在该页面上生成相同的内容。

梅威瑟:

\documentclass[pagesize=pdftex, fontsize=12]{scrbook}
\usepackage[paperwidth=11.2cm, paperheight=17.4cm, top=2cm,bottom=1cm, left=1cm, right=1cm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lettrine}
\usepackage{xltxtra}
\usepackage{tocloft}
\usepackage{etoolbox}
\usepackage[toc]{multitoc}
\usepackage{setspace}
\usepackage{needspace}
\usepackage{calc}
\usepackage{fix2col} %fixes numbering of the sections in the header for two columns

\defaultfontfeatures{Mapping=tex-text}
\setmainfont{Times New Roman}

\usepackage{polyglossia} 
    \setmainlanguage{spanish}

\newcommand{\Sectionnumber}{%
  \sbox\Sectionbox{\smash{\raisebox{-\baselineskip}{%
    \fontsize{2.2\baselineskip}{0}\selectfont\theSection}}\enspace}}

\newcounter{Section}
\newcounter{Subsection}[Section]
\newlength{\Sectionwidth}
\newif\ifFirstSubsection
\newsavebox{\Sectionbox}

\makeatletter
\newcommand{\Section}{%
  \par\vskip\z@ \@plus 2\p@
  \FirstSubsectiontrue\clubpenalty\@M
  \refstepcounter{Section}\stepcounter{Subsection}%
  \Sectionnumber\setlength{\Sectionwidth}{\wd\Sectionbox}%
  \hangindent\Sectionwidth\hangafter-2
  \leavevmode\llap{\box\Sectionbox}\ignorespaces}
\newcommand{\Subsection}{%
  \par\clubpenalty\@clubpenalty
  \ifFirstSubsection
    \ifnum\prevgraf=\@ne\nobreak\hspace*{\Sectionwidth}\fi
    \FirstSubsectionfalse
  \fi
  \refstepcounter{Subsection}\textbf{\theSubsection}\enspace\ignorespaces}
\makeatother

\parindent=0pt
\parskip=0pt

\begin{document}
\frontmatter

\mainmatter

\setcounter{section}{0}

\Section EN el principio crió Dios los cielos y la tierra.
\Subsection Y la tierra estaba desordenada y vacía, y las tinieblas estaban sobre la haz del abismo, y el Espíritu de Dios se movía sobre la haz de las aguas.
\Subsection Y dijo Dios: Sea la luz: y fué la luz.
\Subsection Y vió Dios que la luz era buena: y apartó Dios la luz de las tinieblas.

\Section Y FUERON acabados los cielos y la tierra, y todo su ornamento.
\Subsection Y acabó Dios en el día séptimo su obra que hizo, y reposó el día séptimo de toda su obra que había hecho.
\Subsection Y bendijo Dios al día séptimo, y santificólo, porque en él reposó de toda su obra que había Dios criado y hecho.

\Section EN el principio crió Dios los cielos y la tierra.
\Subsection Y la tierra estaba desordenada y vacía, y las tinieblas estaban sobre la haz del abismo, y el Espíritu de Dios se movía sobre la haz de las aguas.
\Subsection Y dijo Dios: Sea la luz: y fué la luz.
\Subsection Y vió Dios que la luz era buena: y apartó Dios la luz de las tinieblas.

\Section Y FUERON acabados los cielos y la tierra, y todo su ornamento.
\clearpage

\setcounter{Section}{0}
\Section In the beginning God created the heaven and the earth.
\Subsection And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.
\Subsection And God said, Let there be light: and there was light.
\Subsection And God saw the light, that it was good: and God divided the light from the darkness.

\Section Thus the heavens and the earth were finished, and all the host of them.
\Subsection And on the seventh day God ended his work which he had made; and he rested on the seventh day from all his work which he had made.
\Subsection And God blessed the seventh day, and sanctified it: because that in it he had rested from all his work which God created and made.

\Section In the beginning God created the heaven and the earth.
\Subsection And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.
\Subsection And God said, Let there be light: and there was light.
\Subsection And God saw the light, that it was good: and God divided the light from the darkness.

\Section Thus the heavens and the earth were finished, and all the host of them.
\clearpage
\end{document}

答案1

eledpar好吧,事实证明我刚从 CTAN 下载的和版本存在一些问题eledmac。首先,如果你使用该类,就会出现一个严重的错误memoir,但我没有时间研究它。 更新:这个问题已在eledmac 的 github 页面,但尚未进入 CTAN。

尽管如此,eledpar解决这个问题的方法是:

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}%
\usepackage[T1]{fontenc}%
\usepackage[fulloldstylenums,largesmallcaps]{kpfonts}%

\usepackage{eledmac, eledpar,lipsum}

\numberlinefalse% turn off lineation commands (from eledmac)

\usepackage[spanish,english]{babel}

% It seems easier to have 'parallel' Spanish and English sectioning macros
% so that you don't have to worry about one counter for both languages
\newcommand{\SpanSectionnumber}{%
  \sbox\Sectionbox{\smash{\raisebox{-\baselineskip}{%
    \fontsize{2.2\baselineskip}{0}\selectfont\theSpansection}}\enspace}}
\newcommand{\EngSectionnumber}{%
  \sbox\Sectionbox{\smash{\raisebox{-\baselineskip}{%
    \fontsize{2.2\baselineskip}{0}\selectfont\theEngsection}}\enspace}}

\newcounter{Spansection}
\newcounter{Spansubsection}[Spansection]
    \setcounter{Spansection}{0}
\newcounter{Engsection}
\newcounter{Engsubsection}[Engsection]
  \setcounter{Engsection}{0}
\newlength{\Sectionwidth}
\newif\ifFirstSubsection
\newsavebox{\Sectionbox}

\makeatletter
\newcommand{\Spansection}{%
  \par\vskip\z@ \@plus 2\p@
  \FirstSubsectiontrue\clubpenalty\@M
  \refstepcounter{Spansection}\stepcounter{Spansubsection}%
  \SpanSectionnumber\setlength{\Sectionwidth}{\wd\Sectionbox}%
  \hangindent\Sectionwidth\hangafter-2
  \leavevmode\llap{\box\Sectionbox}\ignorespaces}
\newcommand{\Spansubsection}{%
  \par\clubpenalty\@clubpenalty
  \ifFirstSubsection
    \ifnum\prevgraf=\@ne\nobreak\hspace*{\Sectionwidth}\fi
    \FirstSubsectionfalse
  \fi
  \refstepcounter{Spansubsection}\textbf{\theSpansubsection}\enspace\ignorespaces}

\newcommand{\Engsection}{%
  \par\vskip\z@ \@plus 2\p@
  \FirstSubsectiontrue\clubpenalty\@M
  \refstepcounter{Engsection}\stepcounter{Engsubsection}%
  \EngSectionnumber\setlength{\Sectionwidth}{\wd\Sectionbox}%
  \hangindent\Sectionwidth\hangafter-2
  \leavevmode\llap{\box\Sectionbox}\ignorespaces}
\newcommand{\Engsubsection}{%
  \par\clubpenalty\@clubpenalty
  \ifFirstSubsection
    \ifnum\prevgraf=\@ne\nobreak\hspace*{\Sectionwidth}\fi
    \FirstSubsectionfalse
  \fi
  \refstepcounter{Engsubsection}\textbf{\theEngsubsection}\enspace\ignorespaces}
\makeatother

\parindent=0pt
\parskip=0pt

%%% The following are defined only for convenience:
\newcommand{\spanishchunk}{%
\selectlanguage{spanish}
\Spansection EN el principio crió Dios los cielos y la tierra.
\Spansubsection Y la tierra estaba desordenada y vacía, y las tinieblas estaban sobre la haz del abismo, y el Espíritu de Dios se movía sobre la haz de las aguas.
\Spansubsection Y dijo Dios: Sea la luz: y fué la luz.
\Spansubsection Y vió Dios que la luz era buena: y apartó Dios la luz de las tinieblas.

\Spansection Y FUERON acabados los cielos y la tierra, y todo su ornamento.
\Spansubsection Y acabó Dios en el día séptimo su obra que hizo, y reposó el día séptimo de toda su obra que había hecho.
\Spansubsection Y bendijo Dios al día séptimo, y santificólo, porque en él reposó de toda su obra que había Dios criado y hecho.

\Spansection EN el principio crió Dios los cielos y la tierra.
\Spansubsection Y la tierra estaba desordenada y vacía, y las tinieblas estaban sobre la haz del abismo, y el Espíritu de Dios se movía sobre la haz de las aguas.
\Spansubsection Y dijo Dios: Sea la luz: y fué la luz.
\Spansubsection Y vió Dios que la luz era buena: y apartó Dios la luz de las tinieblas.

\Spansection Y FUERON acabados los cielos y la tierra, y todo su ornamento.
}   

\newcommand{\englishchunk}{%
\selectlanguage{english}
\Engsection In the beginning God created the heaven and the earth.
\Engsubsection And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.
\Engsubsection And God said, Let there be light: and there was light.
\Engsubsection And God saw the light, that it was good: and God divided the light from the darkness.

\Engsection Thus the heavens and the earth were finished, and all the host of them.
\Engsubsection And on the seventh day God ended his work which he had made; and he rested on the seventh day from all his work which he had made.
\Engsubsection And God blessed the seventh day, and sanctified it: because that in it he had rested from all his work which God created and made.

\Engsection In the beginning God created the heaven and the earth.
\Engsubsection And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.
\Engsubsection And God said, Let there be light: and there was light.
\Engsubsection And God saw the light, that it was good: and God divided the light from the darkness.

\Engsection Thus the heavens and the earth were finished, and all the host of them.
}

\begin{document}

\begin{pages}

  \begin{Leftside}
  \beginnumbering\pstart
  \spanishchunk\par\spanishchunk\par\spanishchunk
  \pend\endnumbering
  \end{Leftside}

  \begin{Rightside}
  \beginnumbering\pstart
  \englishchunk\par\englishchunk\par\englishchunk
  \pend\endnumbering
  \end{Rightside}

\Pages

  \begin{Leftside}% it might be better to create new environments for these
  \beginnumbering\pstart
  \spanishchunk\par\spanishchunk\par\spanishchunk
  \pend\endnumbering
  \end{Leftside}

  \begin{Rightside}% it might be better to create new environments for these
  \beginnumbering\pstart
  \englishchunk\par\englishchunk\par\englishchunk
  \pend\endnumbering
  \end{Rightside}

\Pages
\end{pages}

\end{document}

为每个文本块创建自己的西班牙语和英语环境可能更明智,但我保留了它们以说明每个“侧面”的必需部分。如果您喜欢平行列,请更改

\begin{pages} 
... 
\Pages 
\end{pages}

到:

\begin{pairs}
...
\Columns
\end{pairs}

答案2

尽管 Stephan Lehmke 已经推荐过这个parallel包,但我想我还是可以补充一下。我曾使用过 parallel 包来描述双语课程。它工作得很好,为我提供了一种向国内外学生提供相同信息的绝佳方式。从我读过的和体验来看,这个包有一些缺点。最令人不安的是列表环境可能会把事情搞得一团糟。我发现我可以使用该hanging包模拟列表环境。在你的情况下,似乎你不太需要列表,但请注意,parallel 包在这方面并不完美,你可能需要找到 LaTeX 通常提供的一些排版功能的替代解决方案。另一个细节是段落是缩进的,所以\noindent如果你需要的话,你需要为第一段添加一个。这是一个 MWE:

\documentclass{article}
\usepackage{parallel,hanging}

\begin{document}

\begin{Parallel}[v]{.47\textwidth}{.47\textwidth}
   \ParallelLText{\noindent Some introductory text in language 1, not to be indented

   \begin{hangparas}{4mm}{1}
      --- Some text in language 1

      --- Some more text in language 1

   \end{hangparas}

   }
   \ParallelRText{\noindent Some introductory text in language 2, not to be indented

   \begin{hangparas}{4mm}{1}
      --- some text in language 2

      --- some more text in language 2
   \end{hangparas}

   }
\end{Parallel}

\end{document}

相关内容