LaTeX 双行双语段落翻译的句子对齐

LaTeX 双行双语段落翻译的句子对齐

我想一次性翻译大型文档的整个段落,并将新句子的开头对齐。以下几乎就是我想要的,尽管它还没有对新句子进行对齐。

\documentclass{article}
\usepackage[margin=1in, paperwidth=8.5in, paperheight=11in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{url}
\usepackage{setspace}
\begin{document}

\def\english{In the heart of the forest lived three little pigs who were brothers. The wolf always was chasing them in order to eat them. In order to escape the wolf, the pigs decided to make a house each. The smallest made his from straw, to finish first and go out to play. The middle one constructed a cottage from wood. Seeing that his little brother had finished already, he hurried to go and play with him. The oldest worked on his house of brick. 'You'll soon see what the wolf does with your houses,' he scolded his brothers but they were having a great time.}

\def\spanish{En el corazón del bosque vivían tres cerditos que eran hermanos. El lobo siempre andaba persiguiéndoles para comérselos. Para escapar del lobo, los cerditos decidieron hacerse una casa. El pequeño la hizo de paja, para acabar antes y poder irse a jugar. El mediano construyó una casita de madera. Al ver que su hermano perqueño había terminado ya, se dio prisa para irse a jugar con él. El mayor trabajaba en su casa de ladrillo. - Ya veréis lo que hace el lobo con vuestras casas - riñó a sus hermanos mientras éstos se lo pasaban en grande.}

\begin{minipage}[t][0pt]{\linewidth}
    \setstretch{3}
    \english
\end{minipage}

\begin{minipage}[t]{\linewidth}
    \setstretch{3}
    \spanish
\end{minipage}

\end{document}

双行翻译示例

我如何自动对齐新句子?为了获得加分,我如何修改此方法以手动指示一个英文句子与两个西班牙语句子对齐的时间?我希望段落自然流畅,我不想在每个句子后添加换行符或使用本质上可以做到这一点的包。

答案1

这是一个巨大的 hack(我不能全心全意地推荐按原样使用它),但这是我能想到的唯一一种不用弄乱 TeX 的换行引擎的方法。你需要将它乳化两次才能使其工作。这也假设西班牙语翻译不会比英语长太多。

\documentclass{article}
\usepackage[margin=1in, paperwidth=8.5in, paperheight=11in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{url}
\usepackage{setspace}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\newcount\numsentences\numsentences=0
\def\sentence#1#2{
  \expandafter\xdef\csname sentenceeng\the\numsentences\endcsname{#1}
  \expandafter\xdef\csname sentenceesp\the\numsentences\endcsname{#2}
  \advance\numsentences by 1
}

\sentence{In the heart of the forest lived three little pigs who were brothers.}
         {En el corazón del bosque vivían tres cerditos que eran hermanos.}
\sentence{The wolf always was chasing them in order to eat them.}
         {El lobo siempre andaba persiguiéndoles para comérselos.}
\sentence{In order to escape the wolf, the pigs decided to make a house each.}
         {Para escapar del lobo, los cerditos decidieron hacerse una casa.}
\sentence{The smallest made his from straw, to finish first and go out to play.}
         {El pequeño la hizo de paja, para acabar antes y poder irse a jugar.}
\sentence{The middle one constructed a cottage from wood.}
         {El mediano construyó una casita de madera.}
\sentence{Seeing that his little brother had finished already, he hurried to go and play with him.}
         {Al ver que su hermano perqueño había terminado ya, se dio prisa para irse a jugar con él.}
\sentence{The oldest worked on his house of brick.}
         {El mayor trabajaba en su casa de ladrillo.}
\sentence{``You'll soon see what the wolf does with your houses,'' he scolded his brothers but they were having a great time.}
         {- Ya veréis lo que hace el lobo con vuestras casas - riñó a sus hermanos mientras éstos se lo pasaban en grande.}

\begin{minipage}[t][0pt]{\linewidth}
  \setstretch{3}
  \count0=-1
  \loop
    \advance\count0 by 1
    \ifnum\count0<\numsentences
      \tikz[remember picture]\coordinate(s\the\count0 begin);\csname sentenceeng\the\count0\endcsname\tikz[remember picture]\coordinate(s\the\count0 end);\hskip0.5in
  \repeat
\end{minipage}

\begin{tikzpicture}[remember picture,overlay]
  \count0=-1
  \loop
    \advance\count0 by 1
    \ifnum\count0<\numsentences
      \path let \p1=(s\the\count0 begin), \p2=(s\the\count0 end) in (s\the\count0 begin) node {\xdef\xpos{\x1}\xdef\ypos{\y1}\xdef\xxpos{\x2}\xdef\yypos{\y2}};
      \ifdim\ypos=\yypos
        \node[below=12pt,left=1mm,anchor=west] at (s\the\count0 begin) {\dimen0=\xxpos\advance\dimen0 by -\xpos\hbox to \dimen0{\csname sentenceesp\the\count0\endcsname\hfill}};
      \else
        \path (current page.west) -- +(1.2in+\oddsidemargin,0) node[coordinate] (leftanchor) {};
        \path let \p1=(leftanchor) in (s\the\count0 begin) node {\xdef\leftxpos{\x1}};
        \path (leftanchor) |- node[below=12pt,left=1mm,anchor=west] {\begin{minipage}[t][0pt]{\linewidth}\setstretch{3}\dimen0=\xpos\advance\dimen0 by -\leftxpos\hspace*{\dimen0}\csname sentenceesp\the\count0\endcsname\end{minipage}} (s\the\count0 begin);
      \fi
  \repeat
\end{tikzpicture}

\end{document}

巨大的黑客看上去是这样的!

答案2

检查两列设置。复制您的英文文本(一些段落)并翻译它们。根据需要插入垂直空间,以对齐段落。

相关内容