2

I'm not referring to tables, just normal paragraphs of text. I want, for example, every other line to be drawn in red, or otherwise highlighted.

My use case is preparing exams for students with special needs.

I thought that something could be worked out maybe calling some TikZ code after the line has been drawn, similar to what packages like lineno do. But that is far beyond my LaTeX skills.

Any help is appreciated.

  • 1
    you mean like tex.stackexchange.com/a/407415/1090 ? – David Carlisle Oct 3 '19 at 14:37
  • Very similar to that, except that I don't want color to change within the line. Thanks for the link anyway, It did not show up in my searches :) So, should I assume this necessarily requires LuaTex? – A. Arredondo Oct 3 '19 at 14:41
3

This is something quickly written with this answer as starting point. It works for plain text but not for equations. Thanks to TikZ' modulo function you could also add a longer color list and alternate between n colors. In principle this can be done without TikZ (e.g. with zrefpos). And it does not require any special compiler like lualatex

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{soul}
\def\lstcolors{"black","red"}
\newcounter{colorindex}
\makeatletter
\DeclareRobustCommand*\myalternate{%
\begin{tikzpicture}[overlay,remember picture]
\path let \p1=($(0,0)-(current page.south)$) in \pgfextra{
\xdef\lasty{\y1}};
\end{tikzpicture}%
\def\SOUL@everytoken{\begin{tikzpicture}[overlay,remember picture]
\path let \p1=($(0,0)-(current page.south)$) in \pgfextra{
\ifdim\y1<\lasty
 \stepcounter{colorindex}
 \xdef\lasty{\y1}
\fi};
\end{tikzpicture}%
\pgfmathsetmacro{\currentcolor}{{\lstcolors}[mod(\number\value{colorindex},2)]}%
\textcolor{\currentcolor}{\the\SOUL@token}}%
\SOUL@}
\makeatother
\begin{document}
\myalternate{hello hello hello hello hello hello hello hello hello hello
hello hello hello hello hello hello hello hello hello hello hello
hello hello hello hello hello hello hello hello hello hello hello
hello hello hello hello hello hello hello hello hello hello hello
hello hello hello hello hello hello hello hello hello hello hello}
\end{document}

enter image description here

  • I forgot to mention that one needs to compile twice. – user194703 Oct 3 '19 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.