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).

Solo plus choir in LilyPond

For a song, I want to have first a solo part (or a unisono part), then afterwards for the refrain or for the coda a full choir part. This is how it works in Lilypond (it may not be the best solution, but one that works).

Define the solo parts:

solo = \relative a' {
   c,4 d e f
   c d e f
   \bar "||"
   \break
}
sololyrics =  \lyricmode {
   la la la la
}

Then define the choir parts just like you normally would (see this post).

And put everything together. We have one voice/staff for the solo and another for the choir. In the choir parts, add a rest for the duration of the solo part to the beginning, in the example we have two measures, so we’ll use R1*2, but if you have more, then just adapt the number:

\score{
<<

   \new Staff <<
      \new Voice = "SoloVoice" << \global \solo >>
      \new Lyrics \lyricsto "SoloVoice" \sololyrics 
   >>

   \new ChoirStaff <<      
      \new Staff  = "Frauen"<<
         \new Voice = "Sopran" { R1*2  \voiceOne  \sopran }
         \new Voice = "Alt" { R1*2  \voiceTwo  \alt }
         \new Lyrics \lyricsto "Sopran" \refrainlyrics 
      >>      
      \new Staff = "Maenner"<<
         \clef bass
         \new Voice = "Tenor" { R1*2  \voiceOne  \tenor }
         \new Voice = "Bass" {  R1*2 \voiceTwo  \bass }
         \new Lyrics \lyricsto "Tenor" \refrainlyrics 
      >>      
   >>
>>

And finally, we need to suppress the empty staves in the beginning, which is done in the layout block:

\layout {
   \context { 
      \Staff
      \RemoveEmptyStaves
      \override VerticalAxisGroup #'remove-first = ##t
   }
}

Adjusting spacing in lilypond

Because I always forget how to do it, this is my default (for explanations see the Lilypond manual):

\paper {
   top-markup-spacing #'basic-distance = #5 % title to page top
   markup-system-spacing #'basic-distance = #15 % first system to title
   system-system-spacing #'basic-distance = #20 % between systems
}

A template for typesetting choir scores in Lilypond

LilyPond is LaTeX for music. You write down the music in a text file, typeset it with LilyPond and the output is a pdf containing sheet music in a beautiful layout. They have very good tutorials at the web page, so head over there to learn more. I just wanted to put my template for choir scores here for future reference.

\version "2.16.0" 


\header {
   title = "Titel"
   composer = "Composer"
}

global = { 
   \key c \major 
   \time 4/4 
}


sopran = \relative c' {
   c4 d e f
   g1   
   \bar "|." 
} 

alt = \relative c' {
   c4 c c c
   c1
} 

tenor = \relative c {
   c4 d e f
   g1
}

bass = \relative c {
   c4 c c c
   c1
}


strophe = \lyricmode {
   Sing -- ing as a test!
} 


% == Part for pdf ==
\score {
<<
   \new ChoirStaff <<
      
      \new Staff  = "Frauen"<<
         \new Voice = "Sopran" { \voiceOne \global  \sopran }
         \new Voice = "Alt" { \voiceTwo \global  \alt }
         \new Lyrics \lyricsto "Sopran" \strophe 
      >>
      
      \new Staff = "Maenner"<<
         \clef bass
         \new Voice = "Tenor" {\voiceOne \global \tenor }
         \new Voice = "Bass" { \voiceTwo \global  \bass }
         \new Lyrics \lyricsto "Tenor" \strophe 
      >>

   >>
>>

\layout {
   indent = 0.0\cm
   \context {\Score 
   }
}

}


% == Part for midi ==
\score { \unfoldRepeats
<<
   \new ChoirStaff <<      
      \new Staff <<
         \new Voice = "Sopran" { \global  \sopran }
      >>
      \new Staff <<
         \new Voice = "Alt" { \global  \alt }
      >>
      \new Staff <<
         \new Voice = "Tenor" { \global  \tenor }
      >>
      \new Staff <<
         \new Voice = "Bass" { \global  \bass }
      >>
   >>
>>
\midi {
   \tempo 4=112
   \set Staff.midiInstrument = "voice oohs" 
}

}

The parts sopran, alt, tenor, bass contain the music for the respective voices. strophe contains the text.

The first score element is for creating the pdf – that’s what the layout part is for. We will have two parallel staves (lines) of music, one for the women voices with a treble clef, one for the men voices with a bass clef. The text will be typeset below each staff, distributed to the notes according to the voices of soprano and tenor.

The second score element is for creating the midi – hence the midi part. Here we separate the four voices into four staves, so that we can turn them on and off separately in a midi player. The unfoldRepeats command is necessary if your piece has voltas (repetitions). You need the command to get the midid to include the repetitions at the places you specify them. Otherwise it will just skip ahead to the next part which is usually not what you want.

That’s it, have fun!

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}

Skip a style for a bar in a bar plot

Let’s say you add five data series to a bar plot and they would get the colors blue – red – brown – gray – purple. Now suppose you have another plot with only four data series, but you would like them to have the colors blue – red – gray – purple, because they are similar to the series 1, 2, 4 and 5 in the first plot. You also don’t want to change the order. What can you do?

The style (colors, markers, etc) for a dataseries are determined by the cycle list in pgfplots. This is a series of style definitions that are applied to your data series one after the other. You can of course define one cycle list for each of the plots and assign the colors the way you want:

\pgfplotscreateplotcyclelist{my five bars}{%
solid,fill,blue, \\%
solid,fill,red, \\%
solid,fill,brown, \\%
solid,fill,gray, \\%
solid,fill,purple, \\%
}
\pgfplotscreateplotcyclelist{my four bars}{%
solid,fill,blue, \\%
solid,fill,red, \\%
solid,fill,gray, \\%
solid,fill,purple, \\%
}

\begin{tikzpicture}
\begin{axis}[cycle list name=my five bars,...]
... add the five data series ...
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[cycle list name=my four bars,...]
... add the four data series ...
\end{axis}
\end{tikzpicture}

But you always need to remember to change both versions. Fortunately there is an easier way! You can shift the index of the cycle list:

\begin{axis}[cycle list name=my five bars,...]
... add first two data series ...
\pgfplotsset{cycle list shift=1} % Skips one style
... add the other two data series ...
\end{axis}
\end{tikzpicture}

Done!

Plot legend in figure caption

If you have a plot and add names to the data series with \addlegendentry{}, a legend is added to the plot that specifies the names for the lines or bars. This is an example plot from my thesis:

\begin{figure}
\begin{tikzpicture}
\begin{axis}[myplot]
\addplot plot coordinates {(1, 0.17) (2, 0.13) (3, 0.09) (4, 0.06) (5, 0.01) (6, 0.01)};
\addlegendentry{System1} % for legend
\addplot plot coordinates {(1, 0.13) (2, 0.16) (3, 0.16) (4, 0.14) (5, 0.14) (6, 0.13)};
\addlegendentry{System2} % for legend
\end{axis}
\end{tikzpicture}
\caption{Results (Precision) at different $k$ for the two systems}
\end{figure}

You can influence the placement and appearance of the legend and it looks really professional. Most of the time that will be exactly what you want. But not always. I wanted the legend to be embedded in the text of the caption (long story why). And this is possible and even quite simple! You just need to define a label for the data series and when you refer to that label, a picture of the line and marker is drawn as the reference.

\begin{figure}
\begin{tikzpicture}
\begin{axis}[myplot]
\addplot plot coordinates {(1, 0.17) (2, 0.13) (3, 0.09) (4, 0.06) (5, 0.01) (6, 0.01)};
\label{tikz:System1}
%\addlegendentry{System1} % remove to get rid of legend
\addplot plot coordinates {(1, 0.13) (2, 0.16) (3, 0.16) (4, 0.14) (5, 0.14) (6, 0.13)};
\label{tikz:System2}
%\addlegendentry{System2}
\end{axis}
\end{tikzpicture}
\caption{Results (Precision) at different $k$ for the two systems \ref{tikz:System1} System 1 and \ref{tikz:System2} System 2}
\end{figure}

Pgfplots is cool!

Hat tip: Stackexchange (the question is about something else)

SVN ignore

Sometimes you have files in your SVN folder that you don’t want to include in the svn. For example let’s say svn status gives the following result:

M       data/data.tex
?       data/data.aux
?       mydoc.bbl
?       mydoc.blg
?       mydoc.log
?       mydoc.out
M       mydoc.tex
M       mydoc.pdf
?       mydoc.toc

All these files are temporary files that LaTeX creates and I don’t want them in my SVN. Is there some way that I don’t have to see them anymore everytime I check what I have changed? YES! There’s a SVN property that you can set for a folder which is called "ignore".

So to ignore all files with the extension aux in the current directory, you can do this:

svn propset svn:ignore *.aux .

But doing that for every one of the five filetypes is already too much for me. Also, the setting applies only to one folder, I would need to repeat the same thing for each subfolder! Fortunately, you can (a) specify a file which contains the stuff to be ignored and (b) call the command recursively on all subfolders. So I write all the things I want to ignore (*.aux, *.bbl, *.blg, *.out, *.toc) into the file ignorethisyoustupidsvn.txt (one pattern per line) and execute the following command:

svn propset svn:ignore -R -F ignorethisyoustupidsvn.txt .

Now let’s do svn status again:

M       data/data.tex
M       mydoc.tex
M       mydoc.pdf

Yay 🙂

Links: SVN properties documentation, Getting svn to ignore files and directories (superchlorine)

Handouts from slides

Creating handouts from slides created with LaTeX beamer is simple. Just specify the option “handout” in the documentclass:

\documentclass[handout]{beamer}

In your slides, you can use the marker presentation and handout to give specific instructions that apply only when the pdf is created in presentation mode or in handout mode. So for example you can have different templates for your slides [there are spaces around the < because otherwise they are not displayed in this blog... delete them when you write real LaTeX]:

\mode < presentation >
{
\usetheme{Madrid}
}
\mode < handout >
{
\usetheme{Szeged}
\usecolortheme{beaver}
}

You can have things only on the handout or only on the slides:

\visible<1->{This is the same for handout and slides.}
\visible<1-|handout:0>{This won't be in the handout.}
\visible<1|handout:2>{This is on the same slide for the presentation,
but on a different slide for the handout.}
\visible<2|handout:1>{This is on a different slide for the presentation,
but on the same slide for the handout.}