Text Formattingusing \pgfmathsetlength to calculate padding; width() function gets wrong answer

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
cypherpunks
Posts: 15
Joined: Sat Dec 10, 2016 12:26 pm

using \pgfmathsetlength to calculate padding; width() function gets wrong answer

Post by cypherpunks »

I have a split 2 column page, one for each language. Using footnotes like normal is a problem because all the footnotes end up below the left column (the french column in this case). Every footnote has a french and english version, so I’ve created a split footnote. The problem is that the padding added to align the footnotes under the right column is not giving expected results.

When there is only one footnote, no problem, because there’s nothing to align. Two or more and we have problems.

Code: Select all

\documentclass{scrartcl}
\usepackage[english,french]{babel}
\usepackage{enumerate}
\usepackage{parcolumns} % needed to get two columns without breaking \begin{enumerate}
\usepackage{footmisc}   % needed to reuse footnotes with labels & references
\usepackage{pgf}        % needed for math calclations
\usepackage{lipsum}

% \bilingual constructs two columns, one for each language, and keeps
% the paragraphs parallel. The “parcolumns” pkg was favored over the
% “parallel” and “paracol” pkgs because /enumerate/ environments are
% possible without messing up the vertical line that divides the two
% columns.
%
%   Left col → French
%   Right col → English
%
% syntax:
%   \bilingual{<French text>}{<English test>}
%
\newcommand{\bilingual}[2]{%
  \colchunk{\selectlanguage{french}#1}%
  \colchunk{\selectlanguage{english}#2}%
  \colplacechunks
}

\newlength{\padding}

% bilingual footnote syntax:
%   \bilingualfn{<tag>}{<French text>}{<English test>}
%
% BUG: \pgfmathsetlength does not correctly calculate \padding
\newcommand{\bilingualfn}[3]{%
  \addtocounter{footnote}{1}%
  \pgfmathsetlength{\padding}{0.5\textwidth-width("#2")}%
  \footnotetext{%
    \emph{(fr)}~\selectlanguage{french}#2\selectlanguage{english}%
    \hspace{\padding}\arabic{footnote}.%
    \emph{(en)}~#3\label{#1}}%
}

\begin{document}

% The footnotes must be declared outside the parcolumns environment or
% things break, but it’s okay to use already defined footnote inside a
% parcolumns.  There’s still a problem: the right column footnotes are
% out of alignment.

\bilingualfn{samplefn}{Cette note est en français}{this footnote is in English}
\bilingualfn{samplefn2}{C’est une autre note en français}{this is another footnote in English}
\bilingualfn{samplefn3}{C'est une troisième note en français}{this is a third footnote in English}

\begin{parcolumns}[rulebetween]{2}
  \bilingual{%
    Cette colonne est en français\\

    \lipsum[1][2-5]
    \begin{enumerate}[a.]
    \item foo\footref{samplefn}
    \item bar\footref{samplefn2}
    \item baz\footref{samplefn3}
    \end{enumerate}
    \lipsum[1][3-6]
  }{%
    This column is in English\\

    \lipsum[1][2-5]
    \begin{enumerate}[a.]
    \item foo\footref{samplefn}
    \item bar\footref{samplefn2}
    \item baz\footref{samplefn3}
    \end{enumerate}
    \lipsum[1][3-6]
  }
\end{parcolumns}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Post Reply