Created
November 6, 2015 22:28
-
-
Save Lenchik/add508381646187b492d to your computer and use it in GitHub Desktop.
Very good Highlighting for pdflatex % http://tex.stackexchange.com/a/220067/79756 Unfortunately only for pdflatex for now
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{minimal} | |
%Very good Highlighting % http://tex.stackexchange.com/a/220067/79756 | |
\usepackage{soulutf8} %PACKAGE %slight modification from ordinary soul. may become more buggy | |
\usepackage{tikz} %PACKAGE | |
\usetikzlibrary{calc} %PACKAGE | |
\usetikzlibrary{decorations.pathmorphing} | |
\makeatletter | |
\newcommand{\defhighlighter}[3][]{% | |
\tikzset{every highlighter/.style={color=#2, fill opacity=#3, #1}}% | |
} | |
\def\highlightcolor{yellow} | |
\defhighlighter{\highlightcolor}{.5} | |
\newcommand{\highlight@DoHighlight}{ | |
\fill [ decoration = {random steps, amplitude=1pt, segment length=15pt} | |
, outer sep = -15pt, inner sep = 0pt, decorate | |
, every highlighter, this highlighter ] | |
($(begin highlight)+(0,8pt)$) rectangle ($(end highlight)+(0,-3pt)$) ; | |
} | |
\newcommand{\highlight@BeginHighlight}{ | |
\coordinate (begin highlight) at (0,0) ; | |
} | |
\newcommand{\highlight@EndHighlight}{ | |
\coordinate (end highlight) at (0,0) ; | |
} | |
\newdimen\highlight@previous | |
\newdimen\highlight@current | |
\DeclareRobustCommand*\highlight[1][]{% | |
\tikzset{this highlighter/.style={#1}}% | |
\SOUL@setup | |
% | |
\def\SOUL@preamble{% | |
\begin{tikzpicture}[overlay, remember picture] | |
\highlight@BeginHighlight | |
\highlight@EndHighlight | |
\end{tikzpicture}% | |
}% | |
% | |
\def\SOUL@postamble{% | |
\begin{tikzpicture}[overlay, remember picture] | |
\highlight@EndHighlight | |
\highlight@DoHighlight | |
\end{tikzpicture}% | |
}% | |
% | |
\def\SOUL@everyhyphen{% | |
\discretionary{% | |
\SOUL@setkern\SOUL@hyphkern | |
\SOUL@sethyphenchar | |
\tikz[overlay, remember picture] \highlight@EndHighlight ;% | |
}{% | |
}{% | |
\SOUL@setkern\SOUL@charkern | |
}% | |
}% | |
% | |
\def\SOUL@everyexhyphen##1{% | |
\SOUL@setkern\SOUL@hyphkern | |
\hbox{##1}% | |
\discretionary{% | |
\tikz[overlay, remember picture] \highlight@EndHighlight ;% | |
}{% | |
}{% | |
\SOUL@setkern\SOUL@charkern | |
}% | |
}% | |
% | |
\def\SOUL@everysyllable{% | |
\begin{tikzpicture}[overlay, remember picture] | |
\path let \p0 = (begin highlight), \p1 = (0,0) in \pgfextra | |
\global\highlight@previous=\y0 | |
\global\highlight@current =\y1 | |
\endpgfextra (0,0) ; | |
\ifdim\highlight@current < \highlight@previous | |
\highlight@DoHighlight | |
\highlight@BeginHighlight | |
\fi | |
\end{tikzpicture}% | |
\the\SOUL@syllable | |
\tikz[overlay, remember picture] \highlight@EndHighlight ;% | |
}% | |
\SOUL@ | |
} | |
\makeatother | |
\newsavebox\tmpbox | |
\usepackage{tabto} %PACKAGE | |
\newcommand\Ohighlight[2][]{% | |
\tabto*{0in}\edef\tmpx{\TabPrevPos}\tabto*{\tmpx}% | |
\savebox\tmpbox{% | |
\begin{minipage}[b]{\textwidth} | |
\tabto*{\tmpx}#2\strut% | |
\end{minipage}}% | |
{\color{\highlightcolor!0}\highlight[#1]{#2}}% | |
\vspace*{\dimexpr-\dp\tmpbox-\ht\tmpbox+\dp\strutbox}% | |
\tabto*{\tmpx}#2\unskip\ % | |
} | |
\textwidth=5in | |
\begin{document} | |
\highlight{The original highlight is drawn over the text. | |
The original definition works over... | |
Multi paragraphs, so my fix should try to as well.} | |
\bigskip | |
\begin{tikzpicture} | |
\node[fill=yellow!50]{with tikz, the highlight is drawn below text but not fancy}; | |
\end{tikzpicture} | |
Now here is my fix. \Ohighlight{The highlight is drawn under the text} | |
Does it work multiline? | |
\Ohighlight[yellow]{The highlight is drawn under the text The highlight is drawn under the text The highlight is drawn under the text The highlight is drawn under the text | |
A new paragraph} | |
And more... | |
\Ohighlight{short} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment