2

I am using BibTeX for my bibliography and everything works as expected. For formatting output I am using natdin, which does almost exactly what I want, except for one or two small things:

It uses -- to denote page ranges, and I'd like to have a spatium before and after the dash, i.e. use \,--\,. When I look into the .bst file, I find this:

FUNCTION {n.dashify}
{ 't :=
  ""
    { t empty$ not }
    { t #1 #1 substring$ "-" =
        { t #1 #2 substring$ "--" = not
            { "--" *
              t #2 global.max$ substring$ 't :=
            }
            {   { t #1 #1 substring$ "-" = }
                { "-" *
                  t #2 global.max$ substring$ 't :=
                }
              while$
            }
          if$
        }
        { t #1 #1 substring$ *
          t #2 global.max$ substring$ 't :=
        }
      if$
    }
  while$
}

Unfortunately I have no idea what this does, exactly, or how to modify it in order to accomplish what I am looking for.

So here's an MWE:

\documentclass[paper=a4]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,ngerman]{babel}
\usepackage[square]{natbib}

\usepackage{lipsum}

\begin{document}
    \section{Lorem Ispum}
        According to \citet{Nescio.2000} we find that 
        \lipsum[1]

    \bibliography{test}
    \bibliographystyle{natdin} 
\end{document}

The accompanying test.bib file contains

@article{Nescio.2000,
 author = {Nescio, Nomen and Public, John Q. and Else, Somebody},
 year = {2000},
 title = {What Miscellaneous Anomaly is This? A Field Guide for the Utterly Confused},
 pages = {95--105},
 volume = {08/15},
 journal = {Internationale Zeitschrift für Tetrapilotomie und Potiosektion}
 }

natdin is widely available on CTAN and used as is.

As you can see in the rendered example, I get S. 95-105 when I really want S.~95\,--\,105.

  • 1
    Either you are using standard BibTeX, and editing a .bst file makes sense, or biblatex, where you can't edit the .bst file but rather alter things in LaTeX. Which is it? – Joseph Wright Nov 3 '13 at 14:48
  • 1
    What happens if you replace { "--" * by { "\,--\," *? (Of course, you do not modify the original style, but copy the file, rename it and change the lines as suggested above.) – moewe Nov 3 '13 at 14:50
  • It is quite confusing that you state you use biblatex and then refer to natdin which is a BibTeX style. Your example snippet is the content of a .bst file though, so I assume you use BibTeX and not biblatex. If you do use biblatex you really should not load natdin or any .bst file for that matter. – moewe Nov 3 '13 at 14:54
  • Sorry for the confusion, it's actually BibTeX. (Can you tell I'm only starting to get the hang of it all?) – Ingmar Nov 3 '13 at 15:10
  • 1
    @moewe The simple fix you suggest doesn't work, since the .bst treats bib entries with pages={n--m} differently from entries with pages={n-m}. The change you suggest will work if the bib entries are like the latter, but not the former. – Alan Munn Nov 3 '13 at 19:17
3

The n.dashify function is used for both page number ranges and other elements like ISBN numbers, so in order to get the style to work the way you want, we need to separate out those two uses in the style. The simplest way to do this is to create a version of the function for page ranges (which we will call n.dashify) and create a new version (like the previous n.dashify which we will call n.dashify.plain. Additionally, we need to change the functions that process non-page number ranges to use the n.dashify.plain function instead of our new function.

First, make a copy of natdin.bst and put it in your local texmf folder (on a TeX Live system this is usually ~/texmf/tex/bibtex/bst (~/Library/texmf/tex/bibtex/bst on a Mac)).

Then, make a copy of the original n.dashify function in the file and give it a new name: n.dashify.plain

Next, replace the old n.dashify function with the following one:

FUNCTION {n.dashify}
{ 't :=
  ""
    { t empty$ not }
    { t #1 #1 substring$ "-" =
        { t #1 #2 substring$ "--" = not
            { "\,--\," *
              t #2 global.max$ substring$ 't :=
            }
            {   { t #1 #1 substring$ "-" = }
                { "" *
                  t #2 global.max$ substring$ 't :=
                }
              while$
             "\,--\," * }
          if$
        }
        { t #1 #1 substring$ *
          t #2 global.max$ substring$ 't :=
        }
      if$
    }
  while$
}

You should now have two n.dashify type functions in the .bst file: n.dashify and n.dashify.plain.

Finally, change the following two functions (which format URLs and ISSN/ISBNs) to use the n.dashify.plain function:

FUNCTION { format.doi.urn }
{ urn empty$
     { doi empty$
          { "" }
          { "DOI" doi n.dashify.plain tie.or.space.connect }
       if$
     }
     { "URN" urn n.dashify.plain tie.or.space.connect }
  if$
}

FUNCTION { format.isbn.issn }
{ isbn empty$
     { issn empty$
          { "" }
          { "ISSN" issn n.dashify.plain tie.or.space.connect }
       if$
     }
     { "ISBN" isbn n.dashify.plain tie.or.space.connect }
  if$
}

Here's a sample document. I've duplicated the bib entries to show the behaviour with pages entries of the form n--m and n-m in the .bib file (see discussion in the comments above) and added some ISBN numbers to check that things work as expected.

\begin{filecontents}{\jobname.bib}
@article{Nescio.2000,
 author = {Nescio, Nomen and Public, John Q. and Else, Somebody},
 year = {2000},
 title = {What Miscellaneous Anomaly is This? A Field Guide for the Utterly Confused},
 pages = {95--105},
 volume = {08/15},
 journal = {Internationale Zeitschrift für Tetrapilotomie und Potiosektion},
 isbn = {1-84356-028-3}
 }
@article{Nescio.2000b,
 author = {Nescio, Nomen and Public, John Q. and Else, Somebody},
 year = {2000},
 title = {What Miscellaneous Anomaly is This? A Field Guide for the Utterly Confused},
 pages = {95-105},
 volume = {08/15},
 journal = {Internationale Zeitschrift für Tetrapilotomie und Potiosektion},
 issn = {1-84356-028-3}
 }
\end{filecontents}
\documentclass[paper=a4]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,ngerman]{babel}
\usepackage[square]{natbib}

\usepackage{lipsum}

\begin{document}
    \section{Lorem Ispum}
        According to \citet{Nescio.2000b,Nescio.2000} we find that 
        \lipsum[1]

    \bibliography{\jobname}
    \bibliographystyle{natdin-copy} 
\end{document}

output of code

  • Thank you very much for this. I have tested this with a full .bib and it works (almost) as expected, the exception being single dashes (such as in ISBN, e.g.) that are now converted to \,--\, as well. I have checked my source, and page numbers will always and reliably be used with -- only, i.e. 95--105. That said, unless this is trivial to fix (and, seriously, what ever is?) I am more than happy with and thankful for the solution provided. – Ingmar Nov 3 '13 at 21:30
  • @Ingmar I thought that might be a problem. It's not too diffucult to fix. I'll update the answer later this evening. – Alan Munn Nov 3 '13 at 21:46
  • @Ingmar I've updated the answer to fix the ISBN issue. – Alan Munn Nov 3 '13 at 22:58
  • Thank you very much, this is exactly what I've been trying to accomplish. You, sir, are a a scholar and a gentleman :-) – Ingmar Nov 4 '13 at 7:00

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.