# paracol and KOMA: Weird Behaviour Depending on Page Break

## Final Update (2018-05-18)

Version 1.34 of paracol with the fix related to this question is availabe on CTAN now.

• I use a KOMA document class in combination with the paracol package.
• The final purpose of the document is a bilingual document (two languages, two synchronized columns).
• In my real document, I color the heading of level subparagraph (here I use red). \addtokomafont{subparagraph}{\color{red}}
• My problem is that the color of the subparagraph on some page break circumstances produces that the normal text is also colored.
• I have trouble narrowing down the problem and making the code minimal: Different page break and the problem/effect is gone.

% Dokumentenklasse inkl. Optionen
\documentclass[
fontsize = 12pt
,parskip = true
,numbers = noendperiod
,chapterprefix = true
]{scrbook}

%% Seitenlayout
\usepackage[
%showframe = true,
showframe = false,
]{geometry}

% Seiten-Dimensionen
\geometry{paperwidth = 300mm} % Format 16:9
\geometry{paperheight = 168.75mm} % Format 16:9
\geometry{margin = 15mm}
\geometry{marginparsep = 2mm}
\geometry{marginparwidth = 8mm}
\geometry{footskip = 14mm}

% Color Support
\usepackage{xcolor}

% paracol
\usepackage{paracol}
\setlength{\columnseprule}{1pt}
\setlength{\columnsep}{2em}

% http://texwelt.de/wissen/fragen/10289/wie-andere-ich-die-abstande-uberunter-section-subsection-subsubsection
\RedeclareSectionCommand[
beforeskip = 0\baselineskip,
afterskip = 1\baselineskip,
innerskip = 0\baselineskip]{chapter}
\RedeclareSectionCommand[
beforeskip = 0\baselineskip,
afterskip = 0.25\baselineskip]{section}
\RedeclareSectionCommand[
beforeskip = 0\baselineskip,
afterskip = 1sp]{subparagraph}

%% Dummy-Texte
\usepackage{blindtext}

\begin{document}

% ### ### ###
\begin{paracol}{2}
% --- --- ---
\begin{leftcolumn*}
% --- ---
% ---

\blindtext
\vspace{10mm}

% ---
% --- ---
\end{leftcolumn*}
% --- --- ---

% --- --- ---
\begin{rightcolumn}
% --- ---
% ---

\blindtext

% ---
% --- ---
\end{rightcolumn}

% --- --- ---
\begin{leftcolumn*}
% --- ---
% ---

\blindtext

% ---
% --- ---
\end{leftcolumn*}
% --- --- ---

% --- --- ---
\begin{rightcolumn}
% --- ---
% ---

\blindtext

% ---
% --- ---
\end{rightcolumn}
% --- --- ---
\end{paracol}
% ### ### ###

\end{document}


Now I edit one line of code, e. g. comment \geometry{margin = 15mm} and get no red normal text:

% Dokumentenklasse inkl. Optionen
\documentclass[
fontsize = 12pt
,parskip = true
,numbers = noendperiod
,chapterprefix = true
]{scrbook}

%% Seitenlayout
\usepackage[
%showframe = true,
showframe = false,
]{geometry}

% Seiten-Dimensionen
\geometry{paperwidth = 300mm} % Format 16:9
\geometry{paperheight = 168.75mm} % Format 16:9
%\geometry{margin = 15mm}
\geometry{marginparsep = 2mm}
\geometry{marginparwidth = 8mm}
\geometry{footskip = 14mm}

% Color Support
\usepackage{xcolor}

% paracol
\usepackage{paracol}
\setlength{\columnseprule}{1pt}
\setlength{\columnsep}{2em}

% http://texwelt.de/wissen/fragen/10289/wie-andere-ich-die-abstande-uberunter-section-subsection-subsubsection
\RedeclareSectionCommand[
beforeskip = 0\baselineskip,
afterskip = 1\baselineskip,
innerskip = 0\baselineskip]{chapter}
\RedeclareSectionCommand[
beforeskip = 0\baselineskip,
afterskip = 0.25\baselineskip]{section}
\RedeclareSectionCommand[
beforeskip = 0\baselineskip,
afterskip = 1sp]{subparagraph}

%% Dummy-Texte
\usepackage{blindtext}

\begin{document}

% ### ### ###
\begin{paracol}{2}
% --- --- ---
\begin{leftcolumn*}
% --- ---
% ---

\blindtext
\vspace{10mm}

% ---
% --- ---
\end{leftcolumn*}
% --- --- ---

% --- --- ---
\begin{rightcolumn}
% --- ---
% ---

\blindtext

% ---
% --- ---
\end{rightcolumn}

% --- --- ---
\begin{leftcolumn*}
% --- ---
% ---

\blindtext

% ---
% --- ---
\end{leftcolumn*}
% --- --- ---

% --- --- ---
\begin{rightcolumn}
% --- ---
% ---

\blindtext

% ---
% --- ---
\end{rightcolumn}
% --- --- ---
\end{paracol}
% ### ### ###

\end{document}


I know that the code is not minimal enough to pass a MWE test. I have trouble providing it.

## Update: Numbered SubParagraph

I made my "MWE" too minimal: I forgot that I have numbered subparagraph . When I incorporate David's code in the originally provided example then I get the desired behaviour.

When I have numbered subparagraph, then the number is not colored.

% Dokumentenklasse inkl. Optionen
\documentclass[
fontsize = 12pt
,parskip = true
,numbers = noendperiod
,chapterprefix = true
]{scrbook}

%% Seitenlayout
\usepackage[
%showframe = true,
showframe = false,
]{geometry}

% Seiten-Dimensionen
\geometry{paperwidth = 300mm} % Format 16:9
\geometry{paperheight = 168.75mm} % Format 16:9
\geometry{margin = 15mm}
\geometry{marginparsep = 2mm}
\geometry{marginparwidth = 8mm}
\geometry{footskip = 14mm}

% Color Support
\usepackage{xcolor}

% paracol
\usepackage{paracol}
\setlength{\columnseprule}{1pt}
\setlength{\columnsep}{2em}

% subparagraph is numberes
\setcounter{secnumdepth}{5}

% Code from David
% -------------------------
\makeatletter
\def\zzz{%
\long\def\sectionlinesformat##1##2##3##4{%
\@hangfrom {\hskip ##2##3}{\textcolor{red}{##4}}}}
\makeatother

% -------------------------

% http://texwelt.de/wissen/fragen/10289/wie-andere-ich-die-abstande-uberunter-section-subsection-subsubsection
\RedeclareSectionCommand[
beforeskip = 0\baselineskip,
afterskip = 1\baselineskip,
innerskip = 0\baselineskip]{chapter}
\RedeclareSectionCommand[
beforeskip = 0\baselineskip,
afterskip = 0.25\baselineskip]{section}
\RedeclareSectionCommand[
beforeskip = 0\baselineskip,
afterskip = 1sp]{subparagraph}

%% Dummy-Texte
\usepackage{blindtext}

\begin{document}

% ### ### ###
\begin{paracol}{2}
% --- --- ---
\begin{leftcolumn*}
% --- ---
% ---

\blindtext
\vspace{10mm}

% ---
% --- ---
\end{leftcolumn*}
% --- --- ---

% --- --- ---
\begin{rightcolumn}
% --- ---
% ---

\blindtext

% ---
% --- ---
\end{rightcolumn}

% --- --- ---
\begin{leftcolumn*}
% --- ---
% ---

\blindtext

% ---
% --- ---
\end{leftcolumn*}
% --- --- ---

% --- --- ---
\begin{rightcolumn}
% --- ---
% ---

\blindtext

% ---
% --- ---
\end{rightcolumn}
% --- --- ---
\end{paracol}
% ### ### ###

\end{document}


## Update (2018-04-27)

I contacted the author of KOMA (Markus Kohm, Germany) and here's summary of what he recommended.

• Better use \sbox instead of \setbox.
• Or use \color@begingroup and \color@endgroup when using \setbox.
• The definition of \sbox shows how it should/could be done.
• In the case of paracol (mad box tricks that span multiple pages) you need to take care of color stack.

I also contacted the author of the paracol package (Hiroshi Nakashima, Japan). He wants to look into it.

I also contacted Heike Oberdiek, the author of color-stack-related packages. He won't be able to look into it in detail though.

## Update (2018-05-03)

The author of the paracol package replied and it doesn't look good for me :). In short: color is a problem (in rare cases like mine) for the current version of paracol.

I investigated your problem to find the following. (1) The root cause is in paracol (i.e., not in KOMA). (2) Fixing the bug in paracol is extremely tough, though I'll try it in future.

Here I show you a little bit lengthy explanation of each issue above.

(1) Root Cause Text coloring is one of toughest implementation issues of paracol because, for example, we have to color some page-crossing lines in left column without interference with coloring in right column. The coloring mechanism in paracol usually works well, but in some unusual cases like your MWE it fails to color texts properly. More specifically, we face a trouble in the following case. (a) A sequence of non-breakable lines is given when a page has too small room to have them as a whole. In your case, the sequence consists of the heading of Section 1.2, that of subparagraph and first two lines of the ordinary paragraph. (b) The sequence has colored paragraphs. In your case, section heading and subparagraph heading are colored (with black and red) and are one-line paragraphs. (c) The sequence could be broken into two pages and the second page
your case, TeX would find a page-break point between the section
and subparagraph headings. When paracol's coloring mechanism sees such a sequence, it inserts a page-break point into the sequence inappropriately, and misunderstands that the coloring of the first line of the second page (subparagraph heading) has started in the first page to cause an improper coloring (reddening all texts following the subparagraph heading).

(2) (Nearly) Perfect Fix Since the problem you faced reveals that the fundamental idea of paracol's coloring mechanism is inappropriate, fixing the bug requires to redesign the mechanism completely even if it is possible. I have an idea for the fix and will examine its feasibility, but I cannot be sure when, or even whether, the fix is incorporated into a future release of paracol.

## Update (2018-05-08)

The author of the paracol package generated a new version (1.34) which will be publicly available in the coming weeks. I got the chance to test it now and with my current actual document: It works within my current document!

## Final Update (2018-05-18)

Version 1.34 of paracol with the fix related to this question is availabe on CTAN now.

• try to replace \color{red} with \textcolor{red} – touhami Apr 9 '18 at 16:32
• @touhami I will test it later. Driving now. Thanks. But textcolor needs an argument as far as I know. That is not useful in this case I think. – Dr. Manuel Kuehner Apr 9 '18 at 16:34
• A way to fix this (but more a quick hacky fix, not tackling the real problem): \newcommand*\colorblack{\color{black}}\addtokomafont{subparagraph}{\color{red}\aftergroup\colorblack}. It works at least in the MWE you gave. – Skillmon Apr 9 '18 at 18:04
• @Skillmon Thanks a lot. If you also find the real problem, my day is even brighter :). – Dr. Manuel Kuehner Apr 9 '18 at 18:05
• I also run into this issue and found, that the oberdieck bundle provides some packages called pdfcol, pdfcolparallel and pdfcolparcolumns, which solved the issue. -- Just saw your edit: why don't you swap the parcol package to parallel or parcolumns and try with Heikos packages? I used KOMA-script by then. – Keks Dose Apr 10 '18 at 7:04

pdftex does warn you

pdfTeX warning: pdflatex: pop empty color page stack 0


If you change the definition to

\makeatletter
\def\zzz{%
\long\def\sectionlinesformat##1##2##3##4{%
\@hangfrom {\hskip ##2##3}{\textcolor{red}{##4}}}}
\makeatother


then the red stays in the heading, without any warnings that the stack is corrupted. the indirect definition inserts a \textcolor just around the text of the heading without disturbing the heading layout code.
• Hello David. I forgot something - in the real document I have \setcounter{secnumdepth}{5} which leads to numbered subparagraph. The number is not part of the color group (not sure if thats technically the correct term) apparently. Should I ask a new question or does this qualify as an update on the question? – Dr. Manuel Kuehner Apr 10 '18 at 7:05