TransWikia.com

How to fix the URL and DOI font? Say, make it smaller

TeX - LaTeX Asked by elge on March 28, 2021

I am using Biblatex to handle the full citations in footnotes and the bibliography. With @online Bibtex/Biblatex entries, I understand the DOI and URL fields in a citation need to be in some special font, often typewriter, to distinguish ‘i’ and ‘l’, for example. However, the font being different and a little larger than the rest, it looks bold to me and I don’t want the URL to be the first thing you notice in a page of an article. How to make the font smaller?

I found some bits here and there that offer another solution (urlstyle{rm} or urlstyle{same}), but it seems to require the url package to be loaded seperately — I am just using Biblatex.

Update: thanks for the comment and the answer. I forgot to mention that I am using a special format, instead of URL I need “en ligne <>”. See the MWE below and correct me if I do this the wrong way. In both situations (urlstyle{same} or UrlFont), I still get the prefix “en ligne” printed with that boldish URL font. Or maybe this is yet another font type. How to fix it all at once? I appreciate the UrlFont method more because it allows me to change the font and the size at the same time. It should also be best to keep a monospace font for URLs and DOIs, too bad they look bold, even when it has been made smaller. Hence smallrm instead of smalltt in the following MWE.

documentclass{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage[english,ngerman,frenchb]{babel}
usepackage{csquotes}

usepackage[style=verbose-trad1,backend=bibtex8]{biblatex}

DeclareFieldFormat{url}{addcolonspacebibstring{en ligne <}url{#1}bibstring{>}}

renewcommand{UrlFont}{smallrm}

addbibresource{biblatex-examples.bib}
begin{document}
nullvfillnoindent
cite{markey}

cite{kastenholz}

printbibliography
end{document}

result

Update 2: Now the icing on the cake (both questions above have been answered), is it possible to make the url and doi font lighter, with some height trick or a color trick (gray or lightgrey)? I appreciate the leo style a lot, especially when you look at the printed result on the page — I don’t have that lighter effect at all when I try it. I can make another post for this if you want.

2 Answers

I figured my long comments to your updated question were not that good so here goes a thorough explanation.

Your redefinition of the url field format contains two sources of error for biblatex.

DeclareFieldFormat{url}{addcolonspacebibstring{en ligne <}url{#1}bibstring{>}}

Firstly, it starts with a command to add a colon and a space before printing any text at all, fortunately biblatex ignores this (there is no unnecessary colon before "en ligne" in your MWE), but we should get rid of it anyway.

Secondly, and more importantly, en ligne < is not actually a bibstring. bibstrings are certain localisation keys that change with the language, so bibstring{editor} prints "editor" in an English, "Herausgeber" in a German and (apparently) "éditeur" in an French document. In order for this to work biblatex has to know these bibstrings and en ligne < is certainly not one of them (neither is > for that matter; a list of standard bibstrings can be found in the biblatex documentation §4.9.2 Localization Keys). Unknown bibstrings will trigger a warning (Bibliography string 'en ligne <' undefined) and their "key" will be printed in bold to clearly notify you in the document that something went wrong.

To print verbose text in biblatex use printtext{foo} instead of bibstring{foo}, but in DeclareFieldFormat printtext is not actually needed, so in this case

DeclareFieldFormat{url}{en ligne <url{#1}>}

might do what you want.

But you can use biblatex's localisation utilities for this.

DefineBibliographyStrings{french}{
  url = {en ligne}
}

Will make sure the bibstring url contains "en ligne" in a French document, so bibstring{url} prints "en ligne" in French and "address" in English.

We can also define a macro mkbiblege analogous to mkbibparens to wrap text in < and >.

makeatletter
newrobustcmd{mkbiblege}[1]{%
  begingroup
  blx@blxinit
  blx@setsfcodes
  <#1>
  endgroup}
makeatother

So we can define

DeclareFieldFormat{url}{bibstring{url}spacemkbiblege{url{#1}}}

Finally, our MWE

documentclass{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage[english,ngerman,frenchb]{babel}
usepackage{csquotes}
usepackage[style=verbose-trad1,backend=bibtex8]{biblatex}

renewcommand{UrlFont}{smallrm}

DefineBibliographyStrings{french}{
  url = {en ligne},
}
DefineBibliographyStrings{german}{
  url = {online},
}

makeatletter
newrobustcmd{mkbiblege}[1]{%
  begingroup
  blx@blxinit
  blx@setsfcodes
  <#1>
  endgroup}
makeatother

DeclareFieldFormat{url}{bibstring{url}spacemkbiblege{url{#1}}}
addbibresource{biblatex-examples.bib}

begin{document}
  nocite{markey}
  printbibliography
end{document}

gives

enter image description here

Correct answer by moewe on March 28, 2021

You can set the UrlFont including a sizing command:

Sample output

documentclass{article}

usepackage{biblatex}
addbibresource{biblatex-examples.bib}

renewcommand{UrlFont}{smallttfamily}

begin{document}

cite{ctan,markey,kastenholz}

printbibliography

end{document}

If you only want this to affect the bibliography, then place the command renewcommand{UrlFont}{smallttfamily} just before printbibliography instead of in the preamble.

Answered by Andrew Swann on March 28, 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