3

I want to access the reference number directly, without making use of natbib or bibtex, but it doesn't work, it always adds the brackets [] around the number.

The reason: for multiple citations it is nice to write [1-3] instead of [1,2,3]. How can I get [1-3] with thebibliography alone?

// solution: adding the package cite via \usepackage{cite} in the preamble automatically converts citations from [1,2,3] to [1-3] which is what I wanted.

Here is the MWE:

\documentclass[12pt, letterpaper]{article}
\usepackage[colorlinks=true]{hyperref}

\begin{document}

Here is a sentence that refers to Refs.~\cite{ref1,ref2,ref3}.

I would also like to refer to these references as [1--3].

The closest I can get is \cite{ref1}--\cite{ref3}.

\begin{thebibliography}{5pt}
  \bibitem{ref1}
    J.~Doe, Some title 1.
  \bibitem{ref2}
    J.~Doe, Some title 2.
  \bibitem{ref3}
    J.~Doe, Some title 3.
\end{thebibliography}

\end{document}
Jens
  • 175
  • 7
  • Could you please add the reason why you don't want to use a package such as natbib or biblatex? – leandriis Jul 15 '19 at 19:19
  • Would adding the cite package be an option for you? – leandriis Jul 15 '19 at 19:20
  • 1
    A good solution™ here does not consist in producing the citation label without brackets and adding -- as well as [ and ] manually. A good solution™ would automatically sort and compress the citation, so that you don't have to worry about doing that. It is possible to write the code to do that, people have done so already and have even gone through the process of producing a package that is available for everyone to use (the cite package and also natbib), so if this question is just about compressed citations, I strongly suggest you load one of those packages. ... – moewe Jul 15 '19 at 19:31
  • 1
    ... Note that cite and to some extent even natbib don't rely on your using .bst files, they can be used with a manual thebibliography. So the fact that you want to use thebibliography is no obstacle here. If there are other reasons why you don't want to use cite or natbib that go beyond what I speculated here, a manual approach might be justified, but it should really be the last resort. – moewe Jul 15 '19 at 19:34
  • 1
    Note that 5pt looks odd as the argument of thebibliography. The mandatory argument to thebibliography should be the longest label in the bibliography, it should not be the width of the longest label (that is to say it should be text and not a length). In case you only have three bibliography items and you use the standard Computer Modern or Latin Modern font you could use any of 1, 2 and 3 as argument (since all digits have the same width in those fonts). But if you have 12 entries, the argument should be 10, 11 or 12. See https://tex.stackexchange.com/q/198330/35864 ... – moewe Jul 15 '19 at 19:38
  • 1
    ... and examples at https://tex.stackexchange.com/q/449462/35864 – moewe Jul 15 '19 at 19:40
  • I prefer to have all my references attached to the individual .tex file with full manual control over the citation style (journal abbreviations etc.) – Jens Jul 15 '19 at 19:49
  • The cite package is perfect for that purpose! Thanks! – Jens Jul 15 '19 at 19:53

1 Answers1

1

for multiple citations it is nice to write [1-3] instead of [1,2,3]. How can I get [1-3] with thebibliography alone?

You can easily achieve your formatting objective for the citation call-outs by loading either the cite package or the natbib package; the latter should be loaded with the options numbers and sort&compress.

Asides:

  • I'm not sure I understand your apparent aversion to loading the natbib or cite citation management packages. For sure, they can be used even if you build the entire bibliography entirely by hand, i.e., without the help of BibTeX or biblatex.

  • The argument of \begin{thebibliography} should be a number such as 9, 99, or 999. I've never before seen 5pt as the argument of \begin{thebibliography}.

enter image description here

\documentclass[12pt, letterpaper]{article}

%% Choose one or the other of the following two lines:
%\usepackage{cite}
\usepackage[numbers,sort&compress]{natbib}

\usepackage[colorlinks,allcolors=blue]{hyperref}

\begin{document}
I can cite all three bib entries as \cite{ref1,ref2,ref3}.

\begin{thebibliography}{5}
  \bibitem{ref1}
    J.~Doe, Some title 1.

  \bibitem{ref2}
    J.~Doe, Some title 2.

  \bibitem{ref3}
    J.~Doe, Some title 3.

\end{thebibliography}
\end{document}
Mico
  • 506,678