As a general comment, you need to specify your code in the order that you want things to appear in the output PDF. That is, if you want something printed on the background, that should be first, followed by what goes on top of it, etc. The output for the PDF is produced in layers, hence the suggested order of usage. So, in your case, I would presume the following should do the trick:
- Write your code containing the highlighting as well as the formulas; and then
- Superimpose the external PDF page on top of your formatting.
[2] above should not influence [1], since there is blank spaces where you want to insert equations, and the highlight should be visible since it is larger than the overlaying text.
As an easy option (in my opinion), the eso-pic
package allows you to specify whether you want to print something in the background (\AddToShipoutPictureBG*
), or in the foreground (\AddToShipoutPictureFG*
). This way you could add the overlay/already-existing PDF using the latter, rather than the former. Or, since you tagged the question pdfpages, I'm guessing that's what you're using to include the pages (via \includepdf
).
If eso-pic
is not your thing, then you'll have play around with positioning the \includepdf
command so that the included PDF page fits overtop of your \pic(<x>,<y>){$...$}
commands. This may be tricky.
As a final though, since you are placing the highlights on a line-by-line basis, you're probably not interested in line-breaking the highlights (which is something that soul
's \hl{...}
does offer). So, you could also just use a coloured box as your "highlighting". Here's how to use coloured boxes (using xcolor
):
\documentclass{article}
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
Here is some text \colorbox{yellow}{\phantom{here is some text}}.%
\end{document}​
You choose the highlighting colour (yellow
in this case), and use \phantom{...}
to remove the text but get the right spacing. Of course, in your example, you will place this text using \pic
.
If your already-created PDF is an image (and therefore whitespace is not transparent), this will not work regardless of what you do, since you won't be able to get in "behind" the text and "in front" of the whitespace.
I'd like to suggest you the \tcbhighmath
command from the tcolorbox
package; its interaction with empheq
will give you the possibility to easily highlight expressions inside the amsmath
environments; a little example:
The code:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{soul}
\usepackage{empheq}
\usepackage[many]{tcolorbox}
\newcommand{\hll}[1]{\colorbox{yellow}{$\displaystyle #1$}}
\tcbset{
highlight math style={
colback=yellow,
arc=0pt,
outer arc=0pt,
boxrule=0pt,
top=2pt,
bottom=2pt,
left=2pt,
right=2pt,
}
}
\begin{document}
\hl{Here is some text, and now we make the observation}
\[
\tcbhighmath{\lim_{n\to\infty}\frac{1}{n}=0.}
\]
\hl{Here is some text, and now we make the observation}
\begin{empheq}[box=\tcbhighmath]{align}
a&=\sin(z)\\
E&=mc^2 + \int_a^b x\, dx
\end{empheq}
\end{document}
If you want to highlight longer elments such as long paragraphs, with possible page breaks, and expressions, then you can use a breakable tcolorbox
. A little example adding to the previous solution a breakable tcolorbox
so now you can highlight individual texts or formulas as well as longer material:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{soul}
\usepackage{empheq}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}% just to generate filler text
\newcommand{\hll}[1]{\colorbox{yellow}{$\displaystyle #1$}}
\tcbset{
myhlight/.style={
colback=yellow,
arc=0pt,
outer arc=0pt,
boxrule=0pt,
top=2pt,
bottom=2pt,
left=2pt,
right=2pt,
},
highlight math style={myhlight}
}
\newtcolorbox{myhl}{
breakable,
myhlight
}
\begin{document}
\hl{Here is some text, and now we make the observation}
\[
\tcbhighmath{\lim_{n\to\infty}\frac{1}{n}=0.}
\]
\hl{Here is some text, and now we make the observation}
\begin{empheq}[box=\tcbhighmath]{align}
a&=\sin(z)\\
E&=mc^2 + \int_a^b x\, dx
\end{empheq}
\begin{myhl}
\lipsum[1-4]
\begin{align}
a&=\sin(z)\\
E&=mc^2 + \int_a^b x\, dx
\end{align}
\lipsum[3]
\end{myhl}
\end{document}
The result:
Best Answer
The soul package (
\usepackage{soul}
) provides\hl
command for highlighting text. But,\cite
,\ref
are not compatible with\hl
and must be placed within an\mbox
in order for\hl
to work properly. An\mbox
also lets soul see the contents as one item.You can use the
\mbox
.At the same time if you want to highlight the reference in the bibliography list, you have to annotate the reference within bibliography file. For instance:
For more information you can refer to soul package documentation: soul package documentation