UPDATE:
The Bounty period is over (AND GUESS WHAT? I gave the credits to the wrong Person (sorry CFR), but thanks Aditya for your contribution. Please upvote CFR answer!!). Find below my current implementation + MWE. If you make improvements to it, please post a reference here as answer/comment This works both for list environments and until page breaks.
Thanks/Contributors:
- Martin Schrarrer: Original Concept
- CFR: For his answer with until end of page underliner + warning (see below)
- David Carlisle: Which helped me with getting Martin/CFR code working on list environments by answering my questions
- Myself :-): For adding the code to handle list environments (totalleftmargin) an printing the current page in the page break warning.
How it looks like (please not it support highlighting, etc as well, see package/second screenshot below)
MWE
\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage{tikzpagelayers-xxx}
\begin{document}
Test \tikzul[red]{Test}
\begin{itemize}
\item Test test test test test test test \tikzul[blue]{also working in list environment}
\end{itemize}
\vspace{7.8cm}
Test Test Test Test Test Test TEst Test Test Test Test \tikzul[green]{Demonstrating underline over pagebreak also working until pagebreak.}
\end{document}
tikzpagelayers-xxx.sty
\ProvidesPackage{tikzpagelayers-xxx}[2016/10/20 v1.0 Hacked version of tikzpagelayers, a package to draw with TikZ before or behind text on the page]
\RequirePackage{tikzpagenodes}
\RequirePackage{atbegshi}
\usetikzlibrary{backgrounds,calc}
\RequirePackage{tikz}
\RequirePackage{zref-abspos}
\newcommand\tikzpagemark{}
\DeclareRobustCommand\tikzpagemark[1]{%
\leavevmode
\zsavepos{tikzpagemark-#1}%
}
\def\tpl@addto#1#2{%
\begingroup
\ifx#1\@undefined
\global\let#1\empty
\else
\ifx#1\relax
\global\let#1\empty
\fi
\fi
\edef\@tempa{\@thetikzpagemark}%
\expandafter\g@addto@macro\expandafter#1\expandafter{%
\expandafter\set@tikzpagemark\expandafter{\@tempa}%
#2%
}%
\endgroup
}
\newenvironment{tikzpagelayer}[2][foreground]{%
\stepcounter{tikzpagemark}%
\tikzpagelayeron
\tikzpagemark{\@thetikzpagemark-begin}%
\expandafter\tpl@addto\csname tikzpagelayer@#1@page\zref@extract{tikzpagemark-\@thetikzpagemark-begin}{abspage}\endcsname{#2}%
\edef\endtikzpagelayer{\noexpand\tikzpagemark{\@thetikzpagemark-end}}%
}{}%
\newcommand{\starttikzpagelayer}[3][foreground]{%
\begingroup
\tikzpagelayeron
\edef\@thetikzpagemark{@#2}%
\tikzpagemark{\@thetikzpagemark-begin}%
\expandafter\tpl@addto\csname tikzpagelayer@#1@page\zref@extract{tikzpagemark-\@thetikzpagemark-begin}{abspage}\endcsname{#3}%
\endgroup
}
\newcommand{\stoptikzpagelayer}[1]{%
\tikzpagemark{@#1-end}%
}%
\newcommand\tikzul[2][]{%
\begingroup
\edef\tmp{%
\noexpand\tikzpagelayer{\noexpand\@tikzul{\the\@totalleftmargin}{tplyshift=-.8\dp\strutbox,#1}}}%
\tmp
#2%
\endtikzpagelayer
\endgroup
}
\newcommand\tikzhl[2][]{%
\begingroup
\tikzpagelayer[background]{\@tikzul{tplyshift=.5\ht\strutbox-.5\dp\strutbox,line width=\baselineskip,yellow,#1}}%
#2%
\endtikzpagelayer
\endgroup
}
\renewcommand\tikzhl[2][]{%
\begingroup
\tikzpagelayer[background]{\draw [line width=.5cm,#1] (tplbegin) -- (tplend);}%
#2%
\endtikzpagelayer
\endgroup
}
\newcommand\tikzshl[2][]{%
\begingroup
\tikzpagelayer[background]{\shade [line width=.5cm,#1] (tplbegin) ++(0,1ex) rectangle (tplend);}%
#2%
\endtikzpagelayer
\endgroup
}
\def\tikzul@loop#1#2#3{%
#3%
\ifdim\dimexpr#1>1.1\baselineskip
#2%
\expandafter\tikzul@loop\expandafter{\the\dimexpr#1-\baselineskip\relax}{#2}%
\fi
}
\tikzset{tplyshift/.code={\def\@tplyshift{#1}}}
\def\tikzullinewidth{\linewidth}
\def\@tikzul#1#2{%
\ifnum\tplfirstpage=\tpllastpage
\draw [#2] let \p1 = (tplbegin), \p2 = (tplend), \p3 = ([xshift=#1]current page text area.south west), \p4 = (current page text area.north east) in
\ifdim\y1=\y2
(\x1,\y1+\@tplyshift) -- (\x2,\y2+\@tplyshift)
\else
(\x1,\y1+\@tplyshift) -- (\x4,\y1+\@tplyshift)
(\x3,\y1+\@tplyshift)
\tikzul@loop{\y1-\y2}{%
++(0,-\baselineskip) -- +(\tikzullinewidth,0)
}{}
(\x3,\y2+\@tplyshift) -- (\x2,\y2+\@tplyshift)
\fi
;
% add code to add stuff to end of current page
\else
\draw [#2] let \p1 = (tplbegin), \p2 = (current page text area.south east), \p3 = ([xshift=#1]current page text area.south west), \p4 = (current page text area.north east) in
\ifdim\y1=\y2
(\x1,\y1+\@tplyshift) -- (\x2,\y2+\@tplyshift)
\else
(\x1,\y1+\@tplyshift) -- (\x4,\y1+\@tplyshift)
(\x3,\y1+\@tplyshift)
\tikzul@loop{\y1-\y2}{%
++(0,-\baselineskip) -- +(\tikzullinewidth,0)
}{}
(\x3,\y2+\@tplyshift) -- (\x2,\y2+\@tplyshift)
\fi
;
\PackageWarning{tikzpagelayers-xxx}{Annotation not continued over page break. Current page \tplfirstpage }%
\fi
}
\newcommand\tikzso[1][]{%
\tikzul[tplyshift=.6ex,#1]%
}
\newcommand\tikzhi[1][]{%
\tikzul[on background layer,tplyshift=.5\ht\strutbox-.5\dp\strutbox,line width=\baselineskip,yellow,#1]%
}
\newenvironment{tpframebox*}[2][]{%
\par
\begingroup
\tikzset{#1}\pgfmathsetmacro\tpframebox@sep{2\fboxsep+\pgflinewidth}
\edef\@tempa{\endgroup\def\noexpand\tpframebox@sep{\tpframebox@sep pt}}%
\@tempa
\vspace{\tpframebox@sep}%
\setlength{\hsize}{#2}%
%\addtolength{\hsize}{-\tpframebox@sep}%
%\addtolength{\hsize}{-\tpframebox@sep}%
\linewidth\hsize
\leftskip=\tpframebox@sep
\rightskip=\tpframebox@sep
\tikzpagelayer{\@tpframebox@s{#1}}%
}{%
\endtikzpagelayer
\par\vspace{\tpframebox@sep}%
}
\newenvironment{tpframebox}[1][]{%
\par
\begingroup
\tikzset{#1}\pgfmathsetmacro\tpframebox@sep{2\fboxsep+\pgflinewidth}
\vspace{\tpframebox@sep pt}%
\edef\@tempa{\endgroup\def\noexpand\tpframebox@sep{\tpframebox@sep}}%
\@tempa
\tikzpagelayer{\@tpframebox{#1}}%
}{%
\endtikzpagelayer
\par\vspace{\tpframebox@sep pt}%
}
\newcommand\newtpfenvironment[6][foreground]{%
\@namedef{@tpfenv@#2@layer}{#1}%
\@namedef{@tpfenv@#2@single}{#3}%
\@namedef{@tpfenv@#2@first}{#4}%
\@namedef{@tpfenv@#2@middle}{#5}%
\@namedef{@tpfenv@#2@last}{#6}%
\newenvironment{#2}{%
\tikzpagelayer[#1]{%
\ifnum\tplfirstpage=\tpllastpage
\csname @tpfenv@#2@single\endcsname
\else
\csname @tpfenv@#2@first\endcsname
\expandafter\tplonlastpage\expandafter{\csname @tpfenv@#2@last\endcsname}%
\expandafter\tplonmiddlepage\expandafter{\csname @tpfenv@#2@middle\endcsname}%
\fi
}%
}{%
\endtikzpagelayer
}%
}
\newtpfenvironment{tpltest}{\draw (tplbegin) -- (tplend);}{}{}{}
\def\@tpframebox#1{%
\begin{scope}[#1]
\ifnum\tplfirstpage=\tpllastpage
\path [#1] let \p1= (tplbegin), \p2 = (tplend), \p3 = (current page text area.north west), \p4 = (current page text area.south east) in
(\x3-\fboxsep-.5\pgflinewidth,\y1+\ht\strutbox+\fboxsep+.5\pgflinewidth) rectangle (\x4+\fboxsep+.5\pgflinewidth,\y2-\dp\strutbox-\fboxsep-.5\pgflinewidth)
;
\else
\path [#1] let \p1= (tplbegin), \p3 = (current page text area.north west), \p4 = (current page text area.south east) in
(\x3-\fboxsep-.5\pgflinewidth,\y4-\dp\strutbox-\fboxsep) -- (\x3-\fboxsep-.5\pgflinewidth,\y1+\ht\strutbox+\fboxsep+.5\pgflinewidth) -| (\x4+\fboxsep+.5\pgflinewidth,\y4-\dp\strutbox-\fboxsep)
;
\tplonpage{\tpllastpage}{%
\begin{scope}[#1]
\path [#1] let \p1 = (tplend), \p3 = (current page text area.north west), \p4 = (current page text area.south east) in
(\x3-\fboxsep-.5\pgflinewidth,\y3+.5\pgflinewidth) --
(\x3-\fboxsep-.5\pgflinewidth,\y1-\dp\strutbox-\fboxsep-.5\pgflinewidth) -|
(\x4+\fboxsep+.5\pgflinewidth,\y3+.5\pgflinewidth)
;
\end{scope}%
}%
\tplonmiddlepages{%
\begin{scope}[#1]
\path [#1,draw=none] let \p1 = (current page text area.north west), \p2 = (current page text area.south east) in
(\x1-\fboxsep-.5\pgflinewidth,\y1+.5\pgflinewidth) --
(\x1-\fboxsep-.5\pgflinewidth,\y2-.5\pgflinewidth) --
(\x2+\fboxsep+.5\pgflinewidth,\y2-.5\pgflinewidth) --
(\x2+\fboxsep+.5\pgflinewidth,\y1+.5\pgflinewidth) -- cycle
;
\path [#1] let \p1 = (current page text area.north west), \p2 = (current page text area.south east) in
(\x1-\fboxsep-.5\pgflinewidth,\y1+.5\pgflinewidth) --
(\x1-\fboxsep-.5\pgflinewidth,\y2-.5\pgflinewidth)
(\x2+\fboxsep+.5\pgflinewidth,\y2-.5\pgflinewidth) --
(\x2+\fboxsep+.5\pgflinewidth,\y1+.5\pgflinewidth)
;
\end{scope}%
}%
\fi
\end{scope}
}
\tikzset{tpframebox/.style={}}
\def\@tpframebox@s#1{%
\begin{scope}[#1]
\ifnum\tplfirstpage=\tpllastpage
\draw [#1] let \p1= (tplbegin), \p2 = (tplend), \p3 = (current page text area.north west), \p4 = (current page text area.south east) in
(\x3+.5\pgflinewidth,\y1+\ht\strutbox+\fboxsep+.5\pgflinewidth) rectangle (\x4-.5\pgflinewidth,\y2-\dp\strutbox-\fboxsep-.5\pgflinewidth)
;
\else
\draw [#1] let \p1= (tplbegin), \p3 = (current page text area.north west), \p4 = (current page text area.south east) in
(\x3-\fboxsep-.5\pgflinewidth,\y4-\dp\strutbox-\fboxsep) -- (\x3-\fboxsep-.5\pgflinewidth,\y1+\ht\strutbox+\fboxsep+.5\pgflinewidth) -| (\x4+\fboxsep+.5\pgflinewidth,\y4-\dp\strutbox-\fboxsep)
;
\fi
\end{scope}
}
\tikzset{tpframebox/.style={}}
\def\set@tikzpagemark#1{%
\def\@thetikzpagemark{#1}%
\edef\tplfirstpage{\zref@extract{tikzpagemark-#1-begin}{abspage}}%
\edef\tpllastpage{\zref@extract{tikzpagemark-#1-end}{abspage}}%
\coordinate (tplbegin) at ([shift={(\zposx{tikzpagemark-#1-begin}sp,\zposy{tikzpagemark-#1-begin}sp)}]current page.south west);%
\coordinate (tplend) at ([shift={(\zposx{tikzpagemark-#1-end}sp,\zposy{tikzpagemark-#1-end}sp)}]current page.south west);%
}
\newcommand\tplonpage[2][foreground]{%
\begingroup
\pgfmathtruncatemacro\@tplpage{#2}%
\expandafter\endgroup
\expandafter\tpl@addto\csname tikzpagelayer@#1@page\@tplpage\endcsname
}
\newcommand\tplonnextpage[1][foreground]{%
\tplonpage[#1]{\@tplnextpage}%
}
\newcommand\tplonlastpage[1][foreground]{%
\tplonpage[#1]{\tpllastpage}%
}
\newcommand\tplonmiddlepages[2][foreground]{%
\begingroup
\@tempcnta=\tplfirstpage\relax
\loop
\advance\@tempcnta\@ne
\ifnum\@tempcnta<\tpllastpage
\tplonpage[#1]{\number\@tempcnta}{#2}%
\repeat
\endgroup
}
% During the page `abspage' is one to low
\def\@tplnextpage{\c@abspage+2}
% In the shipout routine it is correct
\def\@@tplnextpage{\c@abspage+1}
\newcounter{tikzpagemark}
\def\@thetikzpagemark{\number\c@tikzpagemark}
\def\@tikzpagelayeron{%
% \AtBeginShipoutNext{\tikzpagelayer@atbeginshipout}%
% \global\let\tikzpagelayeron\relax
}
\AtBeginShipout{\tikzpagelayer@atbeginshipout}%
\let\tikzpagelayeron\@tikzpagelayeron
\let\tikzpagelayer@background\empty
\let\tikzpagelayer@foreground\empty
\def\tikzpagelayer@atbeginshipout{%
\setbox\AtBeginShipoutBox\hbox{%
\color@setgroup
\let\@tplnextpage\@@tplnextpage
\begin{tikzpicture}[remember picture]%
\path [use as bounding box,every node/.style={},every rectangle node/.style={}]
node [inner sep=0pt,outer sep=0pt] (current page box) {\box\AtBeginShipoutBox};
% \fill [line width=10pt,blue,opacity=.5] (current page box.north west) rectangle (current page box.south east);
\begin{pgfonlayer}{background}
\begin{scope}%
\csname tikzpagelayer@background@page\number\c@abspage\endcsname
\tikzpagelayer@background
\end{scope}%
\end{pgfonlayer}%
\begin{scope}%
\csname tikzpagelayer@foreground@page\number\c@abspage\endcsname
\tikzpagelayer@foreground
\end{scope}%
\end{tikzpicture}%
\color@endgroup
}%
\global\let\tikzpagelayer@background\empty
\global\let\tikzpagelayer@foreground\empty
\global\let\tikzpagelayeron\@tikzpagelayeron
}
START ORIGINAL QUESTION Message
I am looking for a TikZ expert which can give some advice on the following. As I am relatively new to TikZ and this looks like an advanced topic, help would be appreciated.
Context
I am using an excellent featurerich TikZ Highlighter/underline code snippet original developed and posted by Martin Schrarrer. Different other 'forks' are published e.g. this one.
Problem
The original posting/code discuss pagebreaks (see also screenshot below), however it looks not properly implemented. If this TikZ snippet is used at pagebreaks, compilation (second run) will fail with:
! Package tikz Error: Giving up on this path. Did you forget a semicolon?.
As my document is now growing, and this snippet is used more-and-more, more failures occur. Until now I handled this by introducing extra linebreaks or stop/restart this code at page breaks. This become unmanageable.
Minimal Working Example to demonstrate failure
I have added a MWE below. The preamble is untouched (original Martin's code). It breaks at the second compile phase.
Analysis
Ulrike did post below some remarks that the code does contain some bugs. As reported by Ulrike the Martin's original MWE page break only works in his MWE situation (because of special circumstances).
What I am looking for
Which changes are needed to avoid it crashes plus in prefered order:
- Is working on two sided book pagebreaks (left/right margin different)
- Does continue over pagebreaks, but handles two side book document not correctly (preferable log this as well)
- Does not continue over pagebreaks but stops at the end of the page where it did start. Write a warning to log.
- Does not do anything. In case of page breaks in between, no TikZ output appears only a log statement with pagenumber, etc.
MWE producing (on second run) Package tikz Error: Giving up on this path. Did you forget a semicolon?
\documentclass[twoside,11pt]{book}
\usepackage{zref-abspage}
\usepackage{zref-user}
\usepackage{tikz}
\usepackage{atbegshi}
\usetikzlibrary{calc,decorations.pathmorphing}
\makeatletter
\newcommand{\currentsidemargin}{%
\ifodd\zref@extract{textarea-\thetextarea}{abspage}%
\oddsidemargin%
\else%
\evensidemargin%
\fi%
}
\newcounter{textarea}
\newcommand{\settextarea}{%
\stepcounter{textarea}%
\zlabel{textarea-\thetextarea}%
\begin{tikzpicture}[overlay,remember picture]
% Helper nodes
\path (current page.north west) ++(\hoffset, -\voffset)
node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\paperwidth, minimum height=\paperheight]
(pagearea) {};
\path (pagearea.north west) ++(1in+\currentsidemargin,-1in-\topmargin-\headheight-\headsep)
node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\textwidth, minimum height=\textheight]
(textarea) {};
\end{tikzpicture}%
}
\usepackage{lipsum}
\newcommand\xlipsum[1][]{{\let\par\relax\lipsum*[#1]}}
\tikzset{tikzul/.style={yshift=-.75\dp\strutbox}}
\newcounter{tikzul}%
\newcommand\tikzul[1][]{%
\begingroup
\global\tikzullinewidth\linewidth
\def\tikzulsetting{[#1]}%
\stepcounter{tikzul}%
\settextarea
\zlabel{tikzul-begin-\thetikzul}%
\tikz[overlay,remember picture,tikzul] \coordinate (tikzul-\thetikzul) at (0,0);% Modified \tikzmark macro
\ifnum\zref@extract{tikzul-begin-\thetikzul}{abspage}=\zref@extract{tikzul-end-\thetikzul}{abspage}
\else
\AtBeginShipoutNext{\tikzul@endpage{#1}}%
\fi
\bgroup
\def\par{\ifhmode\unskip\fi\egroup\par\@ifnextchar\noindent{\noindent\tikzul[#1]}{\tikzul[#1]\bgroup}}%
\aftergroup\endtikzul
\let\@let@token=%
}
\newlength\tikzullinewidth
\def\tikzul@endpage#1{%
\setbox\AtBeginShipoutBox\hbox{%
\box\AtBeginShipoutBox
\hbox{%
\begin{tikzpicture}[overlay,remember picture,tikzul]
\draw[#1]
let \p1 = (tikzul-\thetikzul), \p2 = ([xshift=\tikzullinewidth+\@totalleftmargin]textarea.south west) in
\ifdim\dimexpr\y1-\y2<.5\baselineskip
(\x1,\y1) -- (\x2,\y1)
\else
let \p3 = ([xshift=\@totalleftmargin]textarea.west) in
(\x1,\y1) -- +(\tikzullinewidth-\x1+\x3,0)
% (\x3,\y2) -- (\x2,\y2)
(\x3,\y1)
\myloop{\y1-\y2+.5\baselineskip}{%
++(0,-\baselineskip) -- +(\tikzullinewidth,0)
}%
\fi
;
\end{tikzpicture}%
}}%
}%
\def\endtikzul{%
\zlabel{tikzul-end-\thetikzul}%
\ifnum\zref@extract{tikzul-begin-\thetikzul}{abspage}=\zref@extract{tikzul-end-\thetikzul}{abspage}
\begin{tikzpicture}[overlay,remember picture,tikzul]
\expandafter\draw\tikzulsetting
let \p1 = (tikzul-\thetikzul), \p2 = (0,0) in
\ifdim\y1=\y2
(\x1,\y1) -- (\x2,\y2)
\else
let \p3 = ([xshift=\@totalleftmargin]textarea.west), \p4 = ([xshift=-\rightmargin]textarea.east) in
(\x1,\y1) -- +(\tikzullinewidth-\x1+\x3,0)
(\x3,\y2) -- (\x2,\y2)
(\x3,\y1)
\myloop{\y1-\y2}{%
++(0,-\baselineskip) -- +(\tikzullinewidth,0)
}%
\fi
;
\end{tikzpicture}%
\else
\settextarea
\begin{tikzpicture}[overlay,remember picture,tikzul]
\expandafter\draw\tikzulsetting
let \p1 = ([xshift=\@totalleftmargin,yshift=-.5\baselineskip]textarea.north west), \p2 = (0,0) in
\ifdim\dimexpr\y1-\y2<.5\baselineskip
(\x1,\y2) -- (\x2,\y2)
\else
let \p3 = ([xshift=\@totalleftmargin]textarea.west), \p4 = ([xshift=-\rightmargin]textarea.east) in
(\x3,\y2) -- (\x2,\y2)
(\x3,\y2)
\myloop{\y1-\y2}{%
++(0,+\baselineskip) -- +(\tikzullinewidth,0)
}
\fi
;
\end{tikzpicture}%
\fi
\endgroup
}
\def\myloop#1#2#3{%
#3%
\ifdim\dimexpr#1>1.1\baselineskip
#2%
\expandafter\myloop\expandafter{\the\dimexpr#1-\baselineskip\relax}{#2}%
\fi
}
\makeatother
\begin{document}
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text \tikzul[green]{text text text text text text text text text
text text text text text text text text text text text
text text text text
text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text} text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
\end{document}




\pgf@picture@serial@countwithout creating a suitable pgfid. In the original code it only works by chance as the following uses of \tikzul hides that the count was off temporarly. – Ulrike Fischer Oct 18 '16 at 09:11.styfile has no licence statement, that it ought not be reposted here and similarly for my patched version. (Strictly speaking, even downloading and using it is probably illegal - never mind patching it - but I'm assuming it wouldn't be on GIT Hub in that case.) – cfr Oct 20 '16 at 22:41\hl{}of the soul package? It is not Tikz, but at least it does highlight correctly over page breaks. You have to make sure that special commands are inside a\mbox{}or you are using\soulregister\command7(e.g.\soulregister\cite7) for all special commands that may appear in the preamble as described in How to make hl highlighting to automatically place incompatible commands in \mbox? – Matthias Arras Oct 22 '16 at 15:49