TransWikia.com

Move entire DOI to the next line rather then sticking into the margin

TeX - LaTeX Asked on July 3, 2021

This builds off a previous question of mine that didn’t get an answer that would work for me. I’ve simplified what I am asking for.

When a DOI in my bibliography extends into the margin, instead of doing that, can it be booted to the next line, and a blank space left on the current line?

Here is an example of the problem: An 8 entry bibliography with 2 entries sticking into the magine as the final part of them is quite long.

Based on the following code:

documentclass{article}

usepackage[width=14cm]{geometry}
usepackage{showframe}
usepackage[style=chem-rsc,doi=true,articletitle=true]{biblatex}

begin{filecontents}[force]{jobname.bib}
@article{VESTA,
author = "Momma, Koichi and Izumi, Fujio",
title = "{{it VESTA3} for three-dimensional visualization of crystal, volumetric and morphology data}",
journal = "J. App. Cryst.",
year = "2011",
volume = "44",
number = "6",
pages = "1272--1276",
doi = {10.1107/S0021889811038970}
}
@Article{Charpin1985,
  author  = {Charpin, P. and Folcher, G. and Lance, M. and Nierlich, M. and Vigner, D.},
  title   = {Structure d'un complexe binucl'{e}aire du nitrate d'uranyle et du N,N-dim'{e}thyl-formamide: (mu)-peroxo-bis[bis(N,N-dim'{e}thyl-formamide)nitratodioxouranium(VI)], [(UO2)2(NO3)2O2(C3H7NO)4]},
  journal = {Acta Crystallogr. Sect.~C: Struct. Chem.},
  year    = {1985},
  volume  = {41},
  number  = {9},
  pages   = {1302--1305},
  doi     = {10.1107/S0108270185007533},
}
@Article{Kawasaki2015,
  author  = {Kawasaki, Takeshi and Kitazawa, Takafumi},
  title   = {Crystal structure of Long Chemical Name Long Chemical Name Long that would need another package to print here asdfasdf},
  journal = {Acta Crystallogr., Sect.~E: Struct. Rep. Online},
  year    = {2015},
  volume  = {71},
  number  = {5},
  pages   = {m122--m123},
  doi     = {10.1107/S2056989015007987},
}
@inproceedings{Meshlab,
    booktitle = {Eurographics Italian Chapter Conference},
    editor = {Vittorio Scarano and Rosario De Chiara and Ugo Erra},
    title = {{MeshLab: an Open-Source Mesh Processing Tool}},
    author = {Cignoni, Paolo and Callieri, Marco and Corsini, Massimiliano and Dellepiane, Matteo and Ganovelli, Fabio and Ranzuglia, Guido},
    year = {2008},
    publisher = {The Eurographics Association},
    ISBN = {978-3-905673-68-5},
    DOI = {10.2312/LocalChapterEvents/ItalChap/ItalianChapConf2008/129-136}
}
@Article{Vittal2011,
  author  = {Leong, Wei Lee and Vittal, Jagadese J.},
  title   = {One-Dimensional Coordination Polymers: Complexity and Diversity in Structures, Properties, and Applications},
  journal = {Chem. Rev.},
  year    = {2011},
  volume  = {111},
  number  = {2},
  pages   = {688--764},
  doi     = {10.1021/cr100160e},
}
@article{Xu2018,
author = {Xu, Wei and Ren, Ya Nan and Xie, Miao and Zhou, Lin Xia and Zheng, Yue Qing},
doi = {10.1039/c7dt04909a},
journal = {Dalton Trans.},
number = {12},
pages = {4236--4250},
publisher = {Royal Society of Chemistry},
title = {{Six uranyl-organic frameworks with naphthalene-dicarboxylic acid and bipyridyl-based spacers: Syntheses, structures, and properties}},
volume = {47},
year = {2018}
}
@Article{HBond,
  author  = {Steiner, Thomas},
  title   = {The Hydrogen Bond in the Solid State},
  journal = {Angew. Chem., Int. Ed.},
  year    = {2002},
  volume  = {41},
  number  = {1},
  pages   = {48--76},
  doi     = {10.1002/1521-3773(20020104)41:1<48::AID-ANIE48>3.0.CO;2-U},
}
@Article{rigu,
  author  = {Thorn, Andrea and Dittrich, Birger and Sheldrick, George M.},
  title   = {Enhanced rigid-bond restraints},
  journal = {Acta Crystallogr. Sect.~A: Foundations and Advances},
  year    = {2012},
  volume  = {68},
  number  = {4},
  pages   = {448--451},
  doi     = {10.1107/S0108767312014535},
}
end{filecontents}
addbibresource{jobname.bib}

begin{document}
How do I get BibLaTeX to stop putting the DOI in the margin?

The first paper is fine, since it breaks nicely into the next line.autocite{VESTA}

However, the next twoautocite{Charpin1985,Kawasaki2015} give me problems since the part of the DOI after the / is so long. 
nocite{*}
printbibliography
end{document}

The multiple examples are included, as I was given code that should do something similar to this last time, but it broke rapidly when given DOIs of different lengths and compositions.

The MWE again, showing what I want to avoid:

documentclass{article}

usepackage[width=14cm]{geometry}
usepackage{showframe}
usepackage[style=chem-rsc,doi=true,articletitle=true]{biblatex}
DeclareFieldFormat{doi}{%
  nobreakhfilpenalty50hbox{}nobreak
  DOIaddcolonaddnbspace
  ifhyperref
    {href{https://doi.org/#1}{nolinkurl{#1}}}
    {nolinkurl{#1}}}

begin{filecontents}[force]{jobname.bib}
@article{VESTA,
author = "Momma, Koichi and Izumi, Fujio",
title = "{{it VESTA3} for three-dimensional visualization of crystal, volumetric and morphology data}",
journal = "J. App. Cryst.",
year = "2011",
volume = "44",
number = "6",
pages = "1272--1276",
doi = {10.1107/S0021889811038970}
}
@Article{Charpin1985,
  author  = {Charpin, P. and Folcher, G. and Lance, M. and Nierlich, M. and Vigner, D.},
  title   = {Structure d'un complexe binucl'{e}aire du nitrate d'uranyle et du N,N-dim'{e}thyl-formamide: (mu)-peroxo-bis[bis(N,N-dim'{e}thyl-formamide)nitratodioxouranium(VI)], [(UO2)2(NO3)2O2(C3H7NO)4]},
  journal = {Acta Crystallogr. Sect.~C: Struct. Chem.},
  year    = {1985},
  volume  = {41},
  number  = {9},
  pages   = {1302--1305},
  doi     = {10.1107/S0108270185007533},
}
@Article{Kawasaki2015,
  author  = {Kawasaki, Takeshi and Kitazawa, Takafumi},
  title   = {Crystal structure of Long Chemical Name Long Chemical Name Long that would need another package to print here asdfasdf},
  journal = {Acta Crystallogr., Sect.~E: Struct. Rep. Online},
  year    = {2015},
  volume  = {71},
  number  = {5},
  pages   = {m122--m123},
  doi     = {10.1107/S2056989015007987},
}
@inproceedings{Meshlab,
    booktitle = {Eurographics Italian Chapter Conference},
    editor = {Vittorio Scarano and Rosario De Chiara and Ugo Erra},
    title = {{MeshLab: an Open-Source Mesh Processing Tool}},
    author = {Cignoni, Paolo and Callieri, Marco and Corsini, Massimiliano and Dellepiane, Matteo and Ganovelli, Fabio and Ranzuglia, Guido},
    year = {2008},
    publisher = {The Eurographics Association},
    ISBN = {978-3-905673-68-5},
    DOI = {10.2312/LocalChapterEvents/ItalChap/ItalianChapConf2008/129-136}
}
@Article{Vittal2011,
  author  = {Leong, Wei Lee and Vittal, Jagadese J.},
  title   = {One-Dimensional Coordination Polymers: Complexity and Diversity in Structures, Properties, and Applications},
  journal = {Chem. Rev.},
  year    = {2011},
  volume  = {111},
  number  = {2},
  pages   = {688--764},
  doi     = {10.1021/cr100160e},
}
@article{Xu2018,
author = {Xu, Wei and Ren, Ya Nan and Xie, Miao and Zhou, Lin Xia and Zheng, Yue Qing},
doi = {10.1039/c7dt04909a},
journal = {Dalton Trans.},
number = {12},
pages = {4236--4250},
publisher = {Royal Society of Chemistry},
title = {{Six uranyl-organic frameworks with naphthalene-dicarboxylic acid and bipyridyl-based spacers: Syntheses, structures, and properties}},
volume = {47},
year = {2018}
}
@Article{HBond,
  author  = {Steiner, Thomas},
  title   = {The Hydrogen Bond in the Solid State},
  journal = {Angew. Chem., Int. Ed.},
  year    = {2002},
  volume  = {41},
  number  = {1},
  pages   = {48--76},
  doi     = {10.1002/1521-3773(20020104)41:1<48::AID-ANIE48>3.0.CO;2-U},
}
@Article{rigu,
  author  = {Thorn, Andrea and Dittrich, Birger and Sheldrick, George M.},
  title   = {Enhanced rigid-bond restraints},
  journal = {Acta Crystallogr. Sect.~A: Foundations and Advances},
  year    = {2012},
  volume  = {68},
  number  = {4},
  pages   = {448--451},
  doi     = {10.1107/S0108767312014535},
}
end{filecontents}
addbibresource{jobname.bib}

begin{document}
In this case, autocite{VESTA} takes a different approach, moving the whole DOI to the next line. 
This allows bothautocite{Charpin1985,Kawasaki2015} to work perfectly. 
However, note what happens further downautocite{Vittal2011,Xu2018}
 with short DOIs getting way to much space. 
 
nocite{*}
printbibliography
end{document}

The same image showing what I want to avoid.

As you can see, bibliographies appear touchy, so I thought it was better to include a few test-cases.
Now, instead of trying to move every DOI that is too long to the next line (as that seems hard, and, to be fair, leaves a ton of extra white space in my references section), I only want to move the DOI down a line if it would protrude into the margin. Oh, and I would like the DOI: to move with it, if possible.

One Answer

I think you want

DeclareFieldFormat{doi}{%
  hfilpenalty50hfilnegspace DOIaddcolonaddnbspace
  ifhyperref
    {href{https://doi.org/#1}{nolinkurl{#1}}}
    {nolinkurl{#1}}}

If the linebreak happens at the penalty, you get hfil to pad out the short line. If it doesn't then the hfil and hfilneg cancel each other so you just get a normal inter-word space from space. If the DOI are definitely short enough to fit on one line you could put an mbox{} around #1 to make sure it doesn't break, as is it could still break if needed.

Correct answer by David Carlisle on July 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP