# Include pages from a pdf into a LaTeX beamer presentation

As you know, I do basically everything with LaTeX. But, I have colleagues who work with other tools and sometimes we exchange slides. Fortunately by now people have realized that I don’t like to get weird formats, so they send me pdfs. Yay!

It is actually really easy to include pages from a presentation in pdf format into a LaTeX beamer presentation. You will need the package pdfpages and then just write:

{
\setbeamercolor{background canvas}{bg=}
\includepdf[pages=3-8]{slides.pdf}
}


The first line is necessary, because it seems like otherwise the pdf slides end up being inserted behind the background of the slides, which doesn’t make so much sense to me, but anyway.

You can also include one pdf page into a beamer-slide (“frame”). This is useful if you want to edit the slide a bit, for example to hack your own footer back into the slide to get consistent page numbering:

{
\setbeamercolor{background canvas}{bg=}
\begin{frame}[t]
\includepdf[pages=3]{slides.pdf}

\vspace{0.81\paperheight} % go down to where we want the footer

\hspace*{0.31\paperwidth} % space to the left
\begin{minipage}{0.6\paperwidth} % insert my footer
\tiny\colorbox{white}{~\insertshortauthor: \insertshorttitle}
\end{minipage}

\end{frame}
}


# Encoding question mark in TikZ

I’m trying to draw the question mark that is sometimes displayed when there are encoding issues: �

This is my solution:

\tikz[baseline=(wi.base)]{
\node[fill=black,rotate=45,inner sep=.1ex,text height=1.8ex,text width=1.8ex] {};
\node[font=\color{white}] (wi) {?};
}


# Marking significance in a bar plot

And still on the topic of LaTeX presentations, this time trying to plot a symbol over a bar to indicate significance.

This is how it works:

\node[xshift=\pgfkeysvalueof{/pgf/bar shift},anchor=south] at (axis cs:Xcoord1,0.47) {$\bullet$};


You need to put this code directly after the point where the data series has been plotted. Example:

\begin{tikzpicture}
\begin{axis}[xtick=data,axis x line*=bottom,axis y line=left,symbolic x coords={Xcoord1, Xcoord2}]

\addplot [ybar,seagreen] coordinates {(Xcoord1, -0.027) (Xcoord2, 0.436)};
\node[xshift=\pgfkeysvalueof{/pgf/bar shift},anchor=south] at (axis cs:Xcoord2,0.47) {$\bullet$};

\addplot+ [ybar,blue] coordinates  {(Xcoord1, 0.331) (Xcoord2, 0.095)};
\node[xshift=\pgfkeysvalueof{/pgf/bar shift},anchor=south] at (axis cs:Xcoord1,0.36) {$\bullet$};

\addplot+ [ybar,orange] coordinates {(Xcoord1, 0.222) (Xcoord2, 0.441)};
\node[xshift=\pgfkeysvalueof{/pgf/bar shift},anchor=south] at (axis cs:Xcoord1,0.25) {$\bullet$};
\node[xshift=\pgfkeysvalueof{/pgf/bar shift},anchor=south] at (axis cs:Xcoord2,0.47) {$\bullet$};
\end{axis}
\end{tikzpicture}


# Overlays for bar charts (take 2)

A while back I posted about using overlays for bar charts to show one value at a time. For my latest presentation I had a similar but slightly different wish: show all values for one system at a time, one system after the other.

Easily done, I just adapt the code from my previous post to show all values at the same time:

\newcommand{\addplotoverlay}[3][]{
\alt<#3->{
}{
\addplot+ [ybar,#1] coordinates {(Xcoord1,0)}; % + don't show zero values in plot
}
}


This is specific to my plot, Xcoord1 is one of my symbolic x-coordinates in the plot. Other than that, the code is completely independent from the used coordinates and the number of them, which makes it more flexible than my old stuff.

Usage (this will let seagreen bars at the given coordinates appear on slide 2):

\addplotoverlayrank[seagreen]{(Xcoord1, 0.331) (Xcoord2, 0.095)}{2}


# LaTeX ‘correct’ and ‘wrong’ symbols with TikZ

A symbol for a checkmark to indicate something is correct:

\newcommand{\correct}{$\color{green}\tikz\fill[scale=0.4](0,.35) -- (.25,0) -- (1,.7) -- (.25,.15) -- cycle;$}


A symbol for a cross to indicate something is wrong:

\newcommand{\wrong}{$\mathbin{\tikz [x=1.4ex,y=1.4ex,line width=.2ex, red] \draw (0,0) -- (1,1) (0,1) -- (1,0);}$}%


You’ll need TikZ for this.

# LaTeX presentation background picture

In one slide of a presentation I wanted to have a background picture and overlay it with several text blocks one after the other to have the effect of the text “coming out of” the background. It is tricky to align things in LaTeX beamer, especially if you want to have them on top of each other, so this is my solution: Two minipages that cover the whole slide on top of each other.

A slide is more or less 7cm high (depending a bit on your template). There probably is a length defined for that, but I was too lazy to look for it so I took the actual value. The width of the slide is of course \textwidth. I use vertically centered alignment for the minipage, but that is up to you (see the post Set height of a minipage for the options you can give to minipage).

The way it now works is the following. Create one minipage of full width and height. Use this to display the background image. Then jump back the full height and create a second minipage of full width and height to display the text inside of that. This is the code for my slide:

\begin{minipage}[c][7cm][c]{\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{img/Reviews}
\end{minipage}

\vspace{-7cm}
\begin{minipage}[c][7cm][c]{\textwidth}
\centering

\visible<2->{
\colorbox{white}{\fbox{\textcolor{blue}{I was impressed by the fast shutter speed of D3200.}\only<3->{\textcolor{darkgreen}{~(\emph{positive})}}}}
}

\vspace{1cm}
\visible<4->{
\colorbox{white}{\fbox{\textcolor{blue}{The autofocus was \textbf{not} so reliable.}\only<5->{\textcolor{red}{~(\emph{negative})}}}}
}
\end{minipage}


# Dependency trees with tikz-dependency

There is a package for drawing dependency trees in LaTeX called tikz-dependency:

\usepackage{tikz-dependency} % draw example with dependency tree


First the sentence is defined inside a deptext environment. You could add more rows to the sentence, e.g., for lemmas or parts-of-speech.
The edges between words are given with depedge commands (outside the deptext environment). Edges can in theory go both ways, but it looks better if they go from the head to the child. Here is an example dependency tree for a sentence:

\begin{dependency}
\begin{deptext}
It \& has \& a \& larger \& LCD \& than \& the \& T3i \& .\\
\end{deptext}
\deproot{3}{ROOT}
\depedge{2}{1}{NMOD}
\depedge{5}{3}{NMOD}
\depedge{5}{4}{NMOD}
\depedge{2}{5}{NMOD}
\depedge{5}{6}{PMOD}
\depedge{8}{7}{AMOD}
\depedge{6}{8}{PRD}
\end{dependency}


Besides drawing dependency trees, the package is also useful to create nice mark-up for words and phrases. The command is wordgroup which is inserted at the same place as the dependency edges and works upon the elements of the deptext The following draws a red box around words 7 and 8 in the sentence above (the 1 stands for the row):

\wordgroup[group style={fill=red!30, draw=red}]{1}{7}{8}{a}


There are lots of styling options for nodes, edges and word groups. I use the following in my thesis (this defines a style that combines options for both the dependency and the deptext environment, I just use the same in both):

\depstyle{depex}{%
edge style = {gray},
group style={inner sep=.2ex},
column sep=0.5em,
edge unit distance=2ex,
row sep=0.2em,
label style={draw=none,font=\scriptsize},
}


I want all mark-up of all word groups to be styled the same way, so I don’t want to write the part with fill and draw all the time with different colors. And if I want to change the percentage of white, I would like to do it at one place for all nodes. So I have written a macro that only expects the color to be given:

\tikzset{
coloring of/.style={fill=#1!30, draw=#1},
}


And finally, for presentations with dependency trees I want to be able to use overlays, i.e., to show a word group at a specific time. For edges you can use the normal \visible command from beamer, but for word groups it does not work for some reason. So this is a macro that does work and shows word groups only on specific slides (I got this from LaTeX Stack Exchange):

\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}},
}


Finally, here an example of using the two macros:

\wordgroup[group style={coloring of=predicatecolor},visible on=<4->]{1}{2}{4}{pred}


# Capitalization and BibTeX

A BibTeX entry is a series of key-value pairs:

@INPROCEEDINGS{KesslerKlingerKuhn2015,
author = {Kessler, Wiltrud and Klinger, Roman and Kuhn, Jonas},
title = {{Towards Opinion Mining from Reviews for the
Prediction of Product Rankings}},
booktitle = "Proceedings of the 6th Workshop on Computational
Approaches to Subjectivity, Sentiment and Social Media
Analysis (WASSA 2015)",
year = 2015,
}


As we see, the values can be enclosed in quotation marks (booktitle), single curly braces (author), double curly braces (title) or nothing (year). What is the difference?

• Nothing: can only be used with an integer value afterwards, e.g., a year.
• Quotation marks "...": Special words like ‘and’ in an author/editor field are processed, capitalization is done according to the bibstyle rules (e.g., all caps, all lowercase, …).
• Single curly braces {...}: Roughly equivalent to quotation marks.
• Double curly braces {{...}}: No special words are processed, capitalization is preserved exactly as given.

The exact results will always depend on your bibliography style. Let’s assume we use apalike and natbib. This particular style abbreviates author’s first names, lowercases titles and preserves the exact capitalization of booktitles/conferences. So the above bibtex entry will result in the citation key (Kessler et al., 2015) and the following bibliography listing:

Kessler, W., Klinger, R., and Kuhn, J. (2015). Towards Opinion Mining from Reviews for the Prediction of Product Rankings. In Proceedings of the 6th Workshop on Computational Approaches to Subjectivity, Sentiment and Social Media Analysis (WASSA 2015).

If we were to use single braces or quotation marks around the title instead of double braces, we’d get the citation key (Kessler et al., 2015) and the bibliography entry

Kessler, W., Klinger, R., and Kuhn, J. (2015). Towards opinion mining from reviews for the prediction of product rankings. In Proceedings of the 6th Workshop on Computational Approaches to Subjectivity, Sentiment and Social Media Analysis (WASSA 2015).

If we were to use double braces around the author instead of single braces, we’d get the citation key (Kessler, Wiltrud and Klinger, Roman and Kuhn, Jonas, 2015) and the bibliography entry

Kessler, Wiltrud and Klinger, Roman and Kuhn, Jonas (2015). Towards opinion mining from reviews for the prediction of product rankings. In Proceedings of the 6th Workshop on Computational Approaches to Subjectivity, Sentiment and Social Media Analysis (WASSA 2015).

So clearly you should never ever use double braces around the author. What about titles? Especially when you have abbreviations or non-English titles it may seem a good idea to use double brackets. But be aware that you essentially disable BibTeX’s normalization of capitalization throughout the bibliography. So if at some point in the future you decide/are forced to use a different style that uses different capitalization rules for the titles, you are screwed.

What is the alternative to get correct capitalization in titles without using double braces? Enclose only the letter that should be capitalized in extra braces. For example if we want to capitalize "Opinion Mining" in the title (just because… no real reason) and be sure that "WASSA" is always all caps, we could do this:

@INPROCEEDINGS{KesslerKlingerKuhn2015,
author = {Kessler, Wiltrud and Klinger, Roman and Kuhn, Jonas},
title = {Towards {O}pinion {M}ining from Reviews for the
Prediction of Product Rankings},
booktitle = "Proceedings of the 6th Workshop on Computational
Approaches to Subjectivity, Sentiment and Social Media
Analysis ({WASSA} 2015)",
year = 2015,
}


And get (Kessler et al., 2015) with:

Kessler, W., Klinger, R., and Kuhn, J. (2015). Towards Opinion Mining from reviews for the prediction of product rankings. In Proceedings of the 6th Workshop on Computational Approaches to Subjectivity, Sentiment and Social Media Analysis (WASSA 2015).

And even for a style that lowercases the booktitle/conference (for whatever strange reason):

Kessler, W., Klinger, R., and Kuhn, J. (2015). Towards Opinion Mining from reviews for the prediction of product rankings. In proceedings of the 6th workshop on computational approaches to subjectivity, sentiment and social media analysis (WASSA 2015).

# Bibentry and duplicate identifiers

I have previously written about listing your publications before the bibliography. This works fine, but there is one problem in combination with document-internal links: An anchor is created at the point where you insert the bibentry. This means that if you click on a citation in the text, you will skip to this location instead of the literature list in the end of the work. Also, you will get errors like this:

l.258 ...a and Blubb, 2014]{BlaBlubb2014}
pdfTeX warning (ext4): destination with the same identifier
(name{cite.BlaBlubb2014}) has been already used, duplicate ignored


The solution is pretty simple, wrap your bibentry-list in a NoHyper environment (HT J-P’s answer at stackexchange):

\begin{NoHyper}\bibentry{BlaBlubb2014}\end{NoHyper}