8

I have the following MWE.

\documentclass{article}
\usepackage[super]{cite}
\usepackage{filecontents}

\begin{filecontents}{samplebib.bib}
    @article{testref1,
        title = {Multiple phase transitions in rare earth tetraborides at low temperature},
        journal = {Solid State Commun.},
        author = {Fisk, Z. and Maple, M. B. and others},
        volume = {39},
        pages = {1189--1192},
        year = {1981},
        doi = {10.1016/0038-1098(81)91111-X}
    }

    @article{testref2,
        title = {Magnetic Structure and Phase Diagram of TmB4},
        author = {{Gab{\'a}ni}, S. and {Ma{\v t}a{\v s}}, S. and others},
        journal = {Acta Phys. Pol., A},
        volume = {113},
        pages = {227--230},
        year = {2008},
        doi = {10.12693/APhysPolA.113.227}
    }

    @article{testref3,
        title = {Classical and quantum routes to linear magnetoresistance},
        author = {Hu, J. and Rosenbaum, T. F.},
        journal = {Nat. Mat.},
        volume = {7},
        pages = {697--700},
        year = {2008},
        doi = {10.1038/nmat2259}
    }
\end{filecontents}

\begin{document}
    This is some text that requires citation\cite{testref1,testref2,testref3}.

    \bibliographystyle{plain}
    \bibliography{samplebib}
\end{document}

with the following output.

example_output


Question

Is it possible to have the cited numbers to be separated, that is:

This is some text that requires citation \textsuperscript{1,2-3}

instead of having it in its current form where it auto-compresses the range of the cited references like "1-3".

Some Extra Info

  • In my actual file, I am using a .bst file which was generated with makebst, and am using scrreprt document class, if that helps.
  • I am using bibtex, if it isn't already clear in the MWE.
  • I do want the default 'style' in my general document to be compressed. It's just that I have this one instance where I want to make a particular reference explicit, instead of being hidden away in a compressed reference list.

Thanks!

3 Answers 3

6

Here is a workaround, by using separate \cite macros, in the form of \cite{testref1}$^,$\cite{testref2,testref3,testref4}. I have encapsulated this in \mcite using the following syntax with & separator:

\mcite{testref1&testref2,testref3,testref4&testref5,testref6,testref7}

Note that I added a references 4-7, since citing reference 2 and 3 together will show as 2,3 and not 2-3. Also, one has to manually deal with punctuation placement.

\documentclass{article}
\usepackage[super]{cite}
\usepackage{filecontents}
\def\ce#1{#1}
\begin{filecontents*}{samplebib.bib}
    @article{testref1,
        title = {Multiple phase transitions in rare earth tetraborides at low temperature},
        journal = {Solid State Commun.},
        author = {Fisk, Z. and Maple, M. B. and others},
        volume = {39},
        pages = {1189--1192},
        year = {1981},
        doi = {10.1016/0038-1098(81)91111-X}
    }

    @article{testref2,
        title = {Magnetic Structure and Phase Diagram of \ce{TmB4}},
        author = {{Gab{\'a}ni}, S. and {Ma{\v t}a{\v s}}, S. and others},
        journal = {Acta Phys. Pol., A},
        volume = {113},
        pages = {227--230},
        year = {2008},
        doi = {10.12693/APhysPolA.113.227}
    }

    @article{testref3,
        title = {Classical and quantum routes to linear magnetoresistance},
        author = {Hu, J. and Rosenbaum, T. F.},
        journal = {Nat. Mat.},
        volume = {7},
        pages = {697--700},
        year = {2008},
        doi = {10.1038/nmat2259}
    }


    @article{testref4,
        title = {Classical and quantum routes to linear magnetoresistance},
        author = {Hu, J. and Rosenbaum, T. F.},
        journal = {Nat. Mat.},
        volume = {7},
        pages = {697--700},
        year = {2008},
        doi = {10.1038/nmat2259}
    }

    @article{testref5,
        title = {Classical and quantum routes to linear magnetoresistance},
        author = {Hu, J. and Rosenbaum, T. F.},
        journal = {Nat. Mat.},
        volume = {7},
        pages = {697--700},
        year = {2008},
        doi = {10.1038/nmat2259}
    }


    @article{testref6,
        title = {Classical and quantum routes to linear magnetoresistance},
        author = {Hu, J. and Rosenbaum, T. F.},
        journal = {Nat. Mat.},
        volume = {7},
        pages = {697--700},
        year = {2008},
        doi = {10.1038/nmat2259}
    }

    @article{testref7,
        title = {Classical and quantum routes to linear magnetoresistance},
        author = {Hu, J. and Rosenbaum, T. F.},
        journal = {Nat. Mat.},
        volume = {7},
        pages = {697--700},
        year = {2008},
        doi = {10.1038/nmat2259}
    }
\end{filecontents*}

\newcommand\mcite[1]{\mcitehelp#1&\relax}
\def\mcitehelp#1&#2\relax{\cite{#1}\ifx\relax#2\relax\else$^,$\mcitehelp#2\relax\fi}
\begin{document}
    This is some text that requires citation.\mcite{testref1&testref2,testref3,testref4&testref5,testref6,testref7}

    \bibliographystyle{plain}
    \bibliography{samplebib}
\end{document}

enter image description here

1
  • Brilliant and elegant solution. (p.s. sorry for forgetting to remove the \ce command). Thanks a lot!
    – ksgj1
    Jan 3, 2017 at 16:08
3

You could define a custom macro that processes the list of cites mantaining the commas like:

\newcommand*\citeuncomp[1]{%
  \textsuperscript{%
    \@for\thereference:=#1\do{\originalcite\thereference},}%
}

while \let\originalcite\cite. To get rid of the trailing comma you could define \def\processcomma{\def\processcomma{,}} and then say:

\newcommand*\citeuncomp[1]{%
  \textsuperscript{%
    \@for\thereference:=#1\do{\processcomma\originalcite\thereference}}%
}

Then you define switchtes that you use inside your text:

\newcommand*\citesuncompressed{\let\cite\citeuncomp\renewcommand*\@citess[1]{##1}}
\newcommand*\citescompressed{\let\cite\originalcite\renewcommand\@citess[1]{\textsuperscript{##1}}}

You could then use the solution like

...
\begin{document}
\citesuncompressed
This is some text that requires citation\cite{testref1,testref2,testref3}.

\citescompressed
This is some text that requires citation\cite{testref1,testref2,testref3}.

\bibliographystyle{plain}
\bibliography{samplebib}
\end{document}

which yelds the following output.

output

Complete Code

\RequirePackage{filecontents}
\begin{filecontents*}{samplebib.bib}
    @article{testref1,
        title = {Multiple phase transitions in rare earth tetraborides at low temperature},
        journal = {Solid State Commun.},
        author = {Fisk, Z. and Maple, M. B. and others},
        volume = {39},
        pages = {1189--1192},
        year = {1981},
        doi = {10.1016/0038-1098(81)91111-X}
    }

    @article{testref2,
        title = {Magnetic Structure and Phase Diagram of \ce{TmB4}},
        author = {{Gab{\'a}ni}, S. and {Ma{\v t}a{\v s}}, S. and others},
        journal = {Acta Phys. Pol., A},
        volume = {113},
        pages = {227--230},
        year = {2008},
        doi = {10.12693/APhysPolA.113.227}
    }

    @article{testref3,
        title = {Classical and quantum routes to linear magnetoresistance},
        author = {Hu, J. and Rosenbaum, T. F.},
        journal = {Nat. Mat.},
        volume = {7},
        pages = {697--700},
        year = {2008},
        doi = {10.1038/nmat2259}
    }
\end{filecontents*}

\documentclass{article}
\usepackage[super]{cite}

\providecommand*\ce[1]{#1}

\makeatletter
\let\originalcite\cite
\def\processcomma{\def\processcomma{,}}
\newcommand*\citeuncomp[1]{%
  \textsuperscript{%
    \@for\thereference:=#1\do{\processcomma\originalcite\thereference}}%
}
\newcommand*\citesuncompressed{\let\cite\citeuncomp\renewcommand*\@citess[1]{##1}}
\newcommand*\citescompressed{\let\cite\originalcite\renewcommand\@citess[1]{\textsuperscript{##1}}}
\makeatother

\begin{document}
\citesuncompressed
This is some text that requires citation\cite{testref1,testref2,testref3}.

\citescompressed
This is some text that requires citation\cite{testref1,testref2,testref3}.

\bibliographystyle{plain}
\bibliography{samplebib}
\end{document}

Addendum

If the order of punctuation matters (i.e. having the dot before the citation) you can define as follows.

\newcommand*\citeuncomp[2]{%
  \gdef\@tempa{#2}%
  \ifx#2.\@tempswatrue\else\@tempswafalse\fi
  \citeunc@mp{#1}%
}
\newcommand*\citeunc@mp[1]{%
  \if@tempswa.\fi%
  \textsuperscript{%
    \@for\thereference:=#1\do{\processcomma\originalcite\thereference}}%
  \if@tempswa\else\@tempa\fi
}

showcase_addendum

1
  • Thanks for your answer! I chose the other answer because I am, in fact, in a situation where I need 1,2-5,9. So the other answer is more suitable. But that is entirely my fault for not specifying. Upvotes all round regardless! :)
    – ksgj1
    Jan 3, 2017 at 16:11
2

We can use the code that cite has internally for the nocompress option to turn things on and off:

\documentclass{article}
\usepackage[super]{cite}
\usepackage[version=4]{mhchem} % As one of the examples needs it!
\usepackage{filecontents}

\begin{filecontents}{samplebib.bib}
    @article{testref1,
        title = {Multiple phase transitions in rare earth tetraborides at low temperature},
        journal = {Solid State Commun.},
        author = {Fisk, Z. and Maple, M. B. and others},
        volume = {39},
        pages = {1189--1192},
        year = {1981},
        doi = {10.1016/0038-1098(81)91111-X}
    }

    @article{testref2,
        title = {Magnetic Structure and Phase Diagram of \ce{TmB4}},
        author = {{Gab{\'a}ni}, S. and {Ma{\v t}a{\v s}}, S. and others},
        journal = {Acta Phys. Pol., A},
        volume = {113},
        pages = {227--230},
        year = {2008},
        doi = {10.12693/APhysPolA.113.227}
    }

    @article{testref3,
        title = {Classical and quantum routes to linear magnetoresistance},
        author = {Hu, J. and Rosenbaum, T. F.},
        journal = {Nat. Mat.},
        volume = {7},
        pages = {697--700},
        year = {2008},
        doi = {10.1038/nmat2259}
    }
\end{filecontents}

\makeatletter
\let\saved@compress@cite\@compress@cite
\protected\def\ActivateCompress{%
  \let\@compress@cite\saved@compress@cite
}
\protected\def\DeactivateCompress{%
    % The following is the code for sort + nocompress from cite.sty
  \def\@compress@cite##1##2##3{%  % This is executed for each number
    \@h@ld \@citea \@cite@out{##3}%
    \let\@h@ld\@empty \let\@citea\citepunct
  }%
}
\makeatother

\begin{document}
    \DeactivateCompress
    This is some text that requires citation\cite{testref1,testref2,testref3}.
    \ActivateCompress
    This is some text that requires citation\cite{testref1,testref2,testref3}.

    \bibliographystyle{plain}
    \bibliography{samplebib}
\end{document}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .