10

I want to underline all titles in a bibliography using the biblatex package with Biber backend and the ulem package. biblatex seems to break ulem's line breaking capabilities. Please consider the following MWE:

\documentclass{article}

\begin{filecontents}{MWE.bib}
    @book{key,
        author = {Super, Max},
        title = {An extraordinary long and meaningless example book title, but unfortunately not correctly wrapped}
    }
\end{filecontents}

\usepackage[normalem]{ulem}
\usepackage[backend=biber]{biblatex}
    \addbibresource{MWE.bib}
    \DeclareFieldFormat*{title}{\uline{#1}}

\begin{document}
    \nocite{*}
    \printbibliography
\end{document}

Is there any workaround? Any help is appreciated.

  • To compose bibliographies are two different styles that you should not mix: one is based on the typewriter that besides monospaced types, makes use of quotation marks and underlined in the absence of other typographic marks. The other style is typographic and makes use of italics, bold and small caps to achieve the same effect. Since LaTeX allows you typographic high quality results, should be consistent with them and ignore those more limited solutions inspired by the typewriter. It is not an answer, it's just an observation and suggestion. – Aradnix Sep 13 '14 at 20:37
  • Beyond matters of style, do not understand why biblatex is not able to split a long text with a command like \uline{...} and it is possible with \emph{...}, \texttt{...} etc. But ulem used out of biblatex is able of splitting. – skpblack Sep 14 '14 at 0:15
  • we need an expert in biblatex. – skpblack Sep 14 '14 at 0:17
  • @Aradnix I don't want to initiate a discussion about style. – DigNative Sep 14 '14 at 9:22
  • @skpblack This is exactly the question that came to my mind. – DigNative Sep 14 '14 at 9:22
6
+50

I found two ways. Using \usefield (biblatex.pdf, page 177)

First way: Redefine bibmacro{title}

The bibmacro{title} is defined in the file biblatex.def as follows:

\newbibmacro*{title}{%
  \ifboolexpr{
    test {\iffieldundef{title}}
    and
    test {\iffieldundef{subtitle}}
  }
    {}
    {\printtext[title]{%
       \printfield[titlecase]{title}%
       \setunit{\subtitlepunct}%
       \printfield[titlecase]{subtitle}}%
     \newunit}%
  \printfield{titleaddon}}

I redefine the bibmacro{title}, in the preamble, as:

\renewbibmacro*{title}{%
  \ifboolexpr{
    test {\iffieldundef{title}}
    and
    test {\iffieldundef{subtitle}}
  }
    {}
    {\printtext{%
     \printtext[titlecase]{\usefield{\uline}{title}}%
     \setunit{\subtitlepunct}%
     \printfield[titlecase]{subtitle}}%
     \newunit}%
  \printfield{titleaddon}}

The MWE:

\documentclass{article}

\begin{filecontents}{MWE.bib}
    @book{key,
        author = {Super, Max},
        title = {An extraordinary long and meaningless example book title, and fortunately correctly wrapped},
        subtitle={A short subtitle},
    }
\end{filecontents}

\usepackage[normalem]{ulem}
\usepackage[backend=biber]{biblatex}
\addbibresource{MWE.bib}

\renewbibmacro*{title}{%
  \ifboolexpr{
    test {\iffieldundef{title}}
    and
    test {\iffieldundef{subtitle}}
  }
    {}
    {\printtext{%
     \printtext[titlecase]{\usefield{\uline}{title}}%
     \setunit{\subtitlepunct}%
     \printfield[titlecase]{subtitle}}%
     \newunit}%
  \printfield{titleaddon}}


\begin{document}
    \nocite{*}
    \printbibliography
\end{document}

enter image description here

EDIT

Second way: Using \DeclareFieldFormat

I found other form using \DeclareFieldFormat and it is not necessary redefine the bibmacro{title}.

The format used in the \printfield{title} is titlecase (In the definition of bibmacro{title}). Then must be redefined this format. This is important because I use \currentfield and it is defined only when used \printfield, not with \printtext.

\DeclareFieldFormat*{titlecase}{
    \ifdef{\currentfield}
      {\ifcurrentfield{title}
         {\usefield{\uline}{\currentfield}}%
         {#1}}
      {#1}}

The \ifdef{\currentfield} is to avoid troubles if the format titlecase is used by a \printtext, for example.

The \ifcurrentfield{title} is to apply the format only to the title field.

Finally, if you would like remove the default emphasis in the title, it is necessary redefine the title format, used by printtext.

\DeclareFieldFormat*{title}{#1}

MWE:

\documentclass{article}

\begin{filecontents}{MWE.bib}
    @book{key,
        author = {Super, Max},
        title = {An extraordinary long and meaningless example book title, and fortunately correctly wrapped},
        subtitle={A short subtitle},
        year={2004},
    }
\end{filecontents}

\usepackage[normalem]{ulem}
\usepackage[backend=biber]{biblatex}
\addbibresource{MWE.bib}

\DeclareFieldFormat*{title}{#1}

\DeclareFieldFormat*{titlecase}{%
    \ifdef{\currentfield}
      {\ifcurrentfield{title}
         {\usefield{\uline}{\currentfield}}%
         {#1}}
      {#1}}

\begin{document}
    \nocite{*}
    \printbibliography
\end{document}

enter image description here

  • 1
    I tried to implement the second solution proposal and it works perfectly! Thank you very much for all your efforts in elaborating and documenting solutions! – DigNative Sep 20 '14 at 7:56
0

Here are some snippets from the ulem documentation that might explain what you are seeing:

Unlike regular underlining, ulem allows line breaks, and manual hyphen- ation, within the underlined text; but it is far from perfect. It is most suit- able for simple text like LATEX: A document preparation system that may need to be underlined in a manuscript submitted for publication. Again, ulem can only give underlined text for \em when the text is delimited by explicit braces.

and:

Every word is typeset in an underlined box, so automatic hyphenation is disabled, but explicit discretionary hyphens (-) will still be obeyed. Several text-formatting commands are specially supported within the un- derlining: -, \ , ~, \, \newline, \linebreak, \nolinebreak, \penalty, \hskip, \hspace, \hfil, \hfill, \hss. Displayed math is not supported. The special commands do have a problem: they end a group so any local assignments are lost.

and:

One important incompatibility with braces and macro replacement: All the text in braces or coming from a macro is typeset in a box (as if in \mbox). Consequently, braces will suppress stretching and line-breaking in the text they enclose. Moreover, the specially-handled commands -, \, \newline and \linebreak are usually ignored if they appear inside extra braces. They operate only when the braces delimit a command parameter without introducing a level of grouping. (Even though braces delimiting command parameters do not normally imply grouping, many commands will add their own grouping.) Thus, you should try to limit inner braces to short bits of text or for delimiting parameters to commands. For emergency repairs, see the sadistic ‘Marat/Sade’ example below. Syntactical spaces inside braces never cause a problem, nor do spaces in math mode.

This documentation can be found as a link to a PDF from here:

http://www.ctan.org/pkg/ulem

I came across a similar problem with underlining in a different situation. The solution I ultimately came up with, which was barely acceptable for me and may not be acceptable to you, was a kludge a found that cycles through the text to be underlined and treats each word separately. This means that each word is underlined but not the spaces between the words. In a bibliography format this may not be appropriate.

The kludge looks like this:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This odd bit plucks words individually
%from a group and undelines each word
%this allows for word-wrapping which otherwise
%does not work well.  The trade off is that
%spaces between words are not underlined
%
\makeatletter
\def\mboxed#1{%
    \@mboxed#1 \@empty
}
\def\@mboxed#1 #2{%
  \uline{#1}\space  % underline from package ulem
   \ifx #2\@empty\else
    \expandafter\@mboxed
   \fi
   #2%
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

(I wish I could take credit for that bit of code or even give proper credit to the actual author, but I can't find the link that lead me to it.)

Which I implement in my situation like this: \newcommand{\role}1{\mboxed{#1}}

I have very little knowledge, unfortunately, of Biblatex, so I'm don't know how or even if this solution could be of any value to you.

  • Thank you very much for your answer and the efforts connected with it. While your workaround allows at least the single words to be underlined, it is a bit disturbing that the blank spaces are not. In this sense, I prefer the solution of @Carlos Lanziano above. Anyway, thank you very much for your detailed answer! – DigNative Sep 20 '14 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.