2

This question continues my another.

I have to use weird margins and line spacing for my academic wirting. MWE:

\documentclass[
               pagesize,
               usegeometry = on,
               DIV = calc,% for the line spacing, KOMA-Script manual, page 40
               ngerman
              ]{scrartcl}

\usepackage[
            left = 25mm,
            bottom = 20mm,
            right = 45mm,
            top = 20mm
           ]{geometry}
\usepackage[onehalfspacing]{setspace}% for the line spacing, KOMA-Script manual, page 40
\usepackage{
            babel,
            csquotes
           }
\usepackage[
            backend = biber,
            sortlocale = auto,
            sorting = nyt,
            style = ext-authoryear-comp
           ]{biblatex}

% for the line spacing, KOMA-Script manual, page 40:
\AfterTOCHead{\singlespacing}
\KOMAoptions{DIV = last}
% adjusting the bibliography
\AtBeginBibliography{\renewcommand*{\mkbibnamegiven}{\textsc}}% small caps for the author name
\AtBeginBibliography{\renewcommand*{\mkbibnamefamily}{\textsc}}% small caps for the author surname
\DeclareFieldFormat{biblabeldate}{#1}% year without the surrounding brackets
\DeclareDelimFormat[bib]{nameyeardelim}{\addcomma\space}% comma before the year
% changes the type @online
\DefineBibliographyStrings{german}{
                                   urlfrom = {verfügbar unter},
                                   urlseen = {zuletzt geprüft am}
                                  }
% changes the format of the fields url and urldate
\DeclareFieldFormat{url}{\bibstring{urlfrom}\addcolon\space\url{#1}}
\DeclareFieldFormat{urldate}{\mkbibbrackets{\bibstring{urlseen}\addcolon\space#1}}
\renewbibmacro*{url+urldate}{% changes the default order of the fields url and urldate
                             \usebibmacro{urldate}%
                             \newunit
                             \usebibmacro{url}%
                            }

\begin{filecontents}{\jobname.bib}

  @ONLINE{Chemie,
          EDITOR   = {LUMITOS GmbH},
          LOCATION = {Berlin},
          URL      = {http://www.chemie.de/lexikon/Kerosin.html},
          TITLE    = {Kerosin},
          URLDATE  = {2018-06-22},
         }

\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}

  Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text \autocite{Chemie}.
  \printbibliography

\end{document}

The result:

breaking

How can I improve the breaking?

Thank you for your help and effort in advance!

  • Is that the output you get from the exact example you posted? I get i.stack.imgur.com/zmgwi.png. You want EDITOR = {{LUMITOS GmbH}}, to fix the "LUMITOS GmbH" right, but I get a nicely broken date. – moewe Jul 19 '18 at 10:56
  • You are missing %s at the end of lines in \renewbibmacro*{url+urldate}, compare with my answer in tex.stackexchange.com/a/441702/35864. – moewe Jul 19 '18 at 10:57
  • Hello @moewe! Yes it is the output from the above code. I added also the % noticed by you (I edited the question). But I get the same output. Yes Lumitos GmbH shouldn't be breaked and the order should stay the same: Lumitos GmbH. Even worse: In my whole document (my academic writing) the output is GmbH, Lumitos and the date stands out, like in the output above. Suggestions? – Su-47 Jul 19 '18 at 11:16
  • Mhhh, it is odd that you should see "LUMITOS GmbH" because the code you use should incorrectly produce "GmbH, LUMITOS" at it did for me. As I said, this can and should be fixed with double braces EDITOR = {{LUMITOS GmbH}},, see tex.stackexchange.com/q/10808/35864. You are still missing a % after \usebibmacro{url}. – moewe Jul 19 '18 at 11:19
  • Hello @moewe! I found the reason for my curious output (I get now the same output as you. Btw: I tested it with the noticed % and it works too.). I described it here. Here it's the same. How ever I don't know how Biber/biblatex could produce the bibliography without this .tcp file. Fact is: Without this file something goes wrong. Thank you for so much information and enormous effort! Now I have to read and test, than I will accept. – Su-47 Jul 19 '18 at 14:19
7

This is a general problem of automatically generated bibliographies. Some bits of the bibliography entry may turn out to be unbreakable and if they happen to occur in the wrong place, ovefull or underfull boxes are the result. And while this is a general problem, there is no universal solution.

Initial state of the corrected MWE (see code below): The "2018]" bit of "[Zuletzt geprüft am: 22. 06. 2018]" protrudes into the margin

The specific issue here is that the entire date "22. 06. 2018" (and the following "].") is a single unbreakable unit. That unit is too long to fit into the first line, but if pushed into the second line in its entirety, the first line would be too sparsely populated for TeX's liking. A possible solution here would be to allow the date to break with

\DefineBibliographyExtras{german}{%
  \protected\def\mkbibdateshort#1#2#3{%
    \iffieldundef{#3}
      {}
      {\mkdayzeros{\thefield{#3}}\adddot
       \iffieldundef{#2}{}{\addthinspace}}%
    \iffieldundef{#2}
      {}
      {\mkmonthzeros{\thefield{#2}}%
       \iffieldundef{#1}
         {}
         {\iffieldundef{#3}{/}{\adddot\addthinspace}}}%
    \iffieldbibstring{#1}
      {\bibstring{\thefield{#1}}}
      {\dateeraprintpre{#1}\mkyearzeros{\thefield{#1}}}}}

But of course that only works for this particular case and it might be undesirable to have the date break across lines (there is after all a reason for the default of non-breaking dates).

"22. 06. 2018" broken in "22. 06." and "2018" so that the margin is preserved

Before we continue, for German texts you definitely want to load \usepackage[T1]{fontenc} if you are using pdfLaTeX (i.e. not when you use XeLaTeX or LuaLaTeX) to enable proper hyphenation of words containing umlauts and other accented characters. Additionally you may want to consider \usepackage{lmodern} instead of the standard Computer European font you get by default, cf. Latin Modern vs cm-super?.

For more generic solutions you can try (in increasing order of effect size and probably decreasing order of desirability)

  1. Load microtype. That package enables use of certain microtypography features that can greatly improve line breaking. Of course microtypography can't solve all (especially big) problems. It doesn't help here, the unbreakable chunk is too large.

    the date still protrudes into right margin - but only the "018]", compared to the initial state the "2" of "2018" is now inside the text area

    Even though microtype did not solve the problem here, it brought a tiny improvement: Initially the entire 2018]. protruded into the margin, now the 2 is inside the text area and only the 018]. crashes the frame.

  2. You can increase \emergencystretch, see What is the meaning of \fussy, \sloppy, \emergencystretch, \tolerance, \hbadness? and Line breaking of URLs in bibliographies, How to use \sloppy for just some references?. In the example

    \begingroup
    \setlength{\emergencystretch}{.5em}
    \printbibliography
    \endgroup
    

    worked. But that value may need to be adjusted for other cases and needs to be found by try and error. Values that are too high may cause unpleasant results.

    slightly larger interword space so that "Zuletzt geprüft am" aligns with the margin, "22. 06. 2018" is in the next line

    The nice thing about \emergencystretch is that it does not influence the line breaking of 'good' paragraphs, i.e. of those that already break and hyphenate nicely (according to TeX's understanding).

  3. Use the option block=space. This places a slightly larger space after each logical block in the bibliography. That space is allowed to grow and shrink and can thus influence the line breaking.

    slightly larger interword space so that "Zuletzt geprüft am" aligns with the margin, "22. 06. 2018" is in the next line

    This happened to work here, because the space required to make the first line 'full enough' for TeX is not very large.

    There is a subtle difference between the output for block=space and the \emergencystretch solution. If you look really closely you will see that not all spaces have the same length with block=space - only the space between "blocks" (units defined by the bibliography driver) is stretched out further than usual. With \emergencystretch all spaces are stretched out equally.

  4. Use \RaggedRight of ragged2e for the bibliography, see also Is there a trick to beautify bibliography?.

    \usepackage{ragged2e}
    ...
    \begingroup
    \RaggedRight
    \printbibliography
    \endgroup
    

    "Zuletzt geprüft am:" does not align with the right margin, interword spaces are not enlarged, "22. 06. 2018" is in the next line, overall impression is ragged right/left aligned

    Note that this typesets the bibliography left aligned (in Word speak) and not justified any more. Note how the line ends do not meet with the frame at the margin. It is incidental to this example that the two lines ends seem to line up here, in general that need not and will not be the case.

  5. Load biblatex with the block=ragged option

    Very ragged right

    This is even more radical than \RaggedRight's left alignment.

Full MWE with all solutions present but commented out

\documentclass[
               pagesize,
               usegeometry = on,
               DIV = calc,
               ngerman
              ]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[
            left = 25mm,
            bottom = 20mm,
            right = 45mm,
            top = 20mm,
            showframe,% to show the frame for the margins
           ]{geometry}
\usepackage[onehalfspacing]{setspace}
\usepackage{
            babel,
            csquotes
           }
\usepackage[
            backend = biber,
            style = ext-authoryear-comp,
            %block=space,% point 2
            %block=ragged,% point 5
           ]{biblatex}

\AfterTOCHead{\singlespacing}
\KOMAoptions{DIV = last}
\AtBeginBibliography{%
  \renewcommand*{\mkbibnamefamily}{\textsc}%
  \renewcommand*{\mkbibnamegiven}{\textsc}%
}

\DeclareFieldFormat{biblabeldate}{#1}
\DeclareDelimFormat[bib]{nameyeardelim}{\addcomma\space}

\DefineBibliographyStrings{german}{
  urlfrom = {verfügbar unter},
  urlseen = {zuletzt geprüft am},
}


\DeclareFieldFormat{url}{\bibstring{urlfrom}\addcolon\space\url{#1}}
\DeclareFieldFormat{urldate}{\mkbibbrackets{\bibstring{urlseen}\addcolon\space#1}}
\renewbibmacro*{url+urldate}{%
  \usebibmacro{urldate}%
  \newunit
  \usebibmacro{url}%
}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@ONLINE{Chemie,
  EDITOR   = {{LUMITOS GmbH}},% this is needed to avoid the name being split into given and family parts
  LOCATION = {Berlin},
  URL      = {http://www.chemie.de/lexikon/Kerosin.html},
  TITLE    = {Kerosin},
  URLDATE  = {2018-06-22},
}
\end{filecontents}
\addbibresource{\jobname.bib}


% for breakable date, remove the \iffalse and \fi to test
\iffalse
\DefineBibliographyExtras{german}{%
  \protected\def\mkbibdateshort#1#2#3{%
    \iffieldundef{#3}
      {}
      {\mkdayzeros{\thefield{#3}}\adddot
       \iffieldundef{#2}{}{\addthinspace}}%
    \iffieldundef{#2}
      {}
      {\mkmonthzeros{\thefield{#2}}%
       \iffieldundef{#1}
         {}
         {\iffieldundef{#3}{/}{\adddot\addthinspace}}}%
    \iffieldbibstring{#1}
      {\bibstring{\thefield{#1}}}
      {\dateeraprintpre{#1}\mkyearzeros{\thefield{#1}}}}}
\fi

% point 1
%\usepackage{microtype}

% for point 4
%\usepackage{ragged2e}

\begin{document}
  Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text. Text \autocite{Chemie}.

\printbibliography

% point 3
%\begingroup
%\setlength{\emergencystretch}{.5em}
%\printbibliography
%\endgroup

% point 4
%\begingroup
%\RaggedRight
%\printbibliography
%\endgroup
\end{document}

I removed your comments to make mine more visible and show where the % is needed to avoid unwanted space, see What is the use of percent signs (%) at the end of lines?. Note also that I removed the default settings sortlocale=auto and sorting=nyt and that I added the necessary braces for the corporate author "LUMITOS GmbH", see Using a 'corporate author' in the "author" field of a bibliographic entry (spelling out the name in full).

  • A very competent and fleshed out answer. Have my upvote! – Oleg Lobachev Jul 19 '18 at 19:47
  • Hello @moewe! Thank you for your great answer! I used microtype and block = space and it was enough. I wish to say sorry for the long delay! Tomorrow is the deadline for my academic writing and now it is ready, except of one diagram. – Su-47 Jul 29 '18 at 15:23

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.