# Uncompressing cite references locally (with square brackets)

I am in a similar situation as described in this question: uncompressing cite references locally, but I have a slight complication. I think it is preferable to start a new question instead of leaving a comment on the original one. So here goes:

## Problem

I need to uncompress a cited reference locally (just this one occasion), such that instead of ...needs citation [1-5], I have something like ...needs citation [1,2-5]. Notice that ref. 1 is now separated from the main 'group' of references. See the MWE below.

## MWE and attempt

Consider the following MWE (slightly modified from the one in the above link, and one of the solution from that link is applied below):

\documentclass{article}
\usepackage{cite}
\usepackage{hyperref,cleveref} % I am using these packages as well
\usepackage{filecontents}

% References
\begin{filecontents}{samplebib.bib}
@article{testref1,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
@article{testref2,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
@article{testref3,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
@article{testref4,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
@article{testref5,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
\end{filecontents}

\makeatletter % Cite references to be in square brackets, superscript
\renewcommand{\@cite}[1]{\textsuperscript{[#1]}}
\makeatother

% The accepted solution from the original question - Credit to Steven B. Segletes
% \newcommand\mcite[1]{\expandafter\mcitehelp\noexpand#1&\relax} % (Old)
\newcommand\mcite[1]{\mcitehelp#1&\relax}  % (Updated Code)
\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}.

But this is unsatisfactory because I'd prefer it to look like:

This is some text that requires citation \textsuperscript{[1,\,2--5]}.

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


A quick look at the output:

I left the \hyperref and \cleveref packages in the MWE because hopefully your answer will not interfere with my use of these packages.

I am aware that \cite has the option \uncompress but that is unsatisfactory because:

• That applies throughout the document. I only need this once.
• It lists all the references singularly ([1],[2],[3],[4],[5]), which I don't want. I only want one reference to be isolated from the group. The rest should stay grouped.

## Question

So I guess my question is, can I get some help with modifying the code so that I can achieve the desired output? I'm still rather new to programming with LaTeX. Thank you!

TL;DR: I want an uncompressed cited reference, just like how the cleveref package allows with \cref{label1, ,label2,label3,label4} for normal labels, which will give me an output like the one in the picture (bottom one).

• FYI, unrelated to this question, I edited my answer on the cited question... \newcommand\mcite[1]{\mcitehelp#1&\relax} is now defined more simply. – Steven B. Segletes Jan 5 '17 at 11:48
• Updated for the benefit of others in the future. Must've missed it -thanks! By any chance, are you able to come up with something similar in my particular case? Not that the current answer by Ulrike Fischer is not satisfactory tho :x – Troy Jan 5 '17 at 12:35

I removed hyperref for the screenshot, but it works with it too.

\documentclass{article}
\usepackage{cite}
%\usepackage{hyperref,cleveref} % I am using these packages as well
\usepackage{filecontents}

% References
\begin{filecontents}{samplebib.bib}
@article{testref1,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
@article{testref2,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
@article{testref3,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
@article{testref4,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
@article{testref5,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
\end{filecontents}

\makeatletter % Cite references to be in square brackets, superscript
\renewcommand{\@cite}[1]{\textsuperscript{[#1]}}
\makeatother

\begin{document}
This is some text that requires citation%
\begingroup
\makeatletter
\renewcommand{\@cite}[1]{#1}%
\textsuperscript{[\cite{testref1},\,\cite{testref2, testref3, testref4, testref5}]}.
\endgroup

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


• I do believe it should be \makeatother at the end. But it works great as an ad-hoc solution. Thanks! – Troy Jan 5 '17 at 12:27
• There should be nothing at the end (the group ends the \makeatletter anyway). – Ulrike Fischer Jan 5 '17 at 13:21

I suggest you switch from using the cite citation management package to using the natbib citation management package. The natbib package should be loaded with the options super, square, comma, and sort&compress.

This permits setting up a new dedicated citation macro -- called \mcitex in the code below -- that takes two arguments: bib entries before and after a separating comma. The entries in each of the arguments will be sorted and compressed as usual.

\RequirePackage{filecontents}
\begin{filecontents}{samplebib.bib}
@article{testref1,
title = {Test title}, journal = {Test Journal},
author = {Test authors and others}, volume=1, year=2016}
@article{testref2,
title = {Test title}, journal = {Test Journal},
author = {Test authors and others}, volume=2, year=2017}
@article{testref3,
title = {Test title}, journal = {Test Journal},
author = {Test authors and others}, volume=3, year=2018}
@article{testref4,
title = {Test title}, journal = {Test Journal},
author = {Test authors and others}, volume=4, year=2019}
@article{testref5,
title = {Test title}, journal = {Test Journal},
author = {Test authors and others}, volume=5, year=2020}
@article{testref6,
title = {Test title}, journal = {Test Journal},
author = {Test authors and others}, volume=6, year=2021}

\end{filecontents}

\documentclass{article}
\usepackage[super,square,comma,sort&compress]{natbib}
\bibliographystyle{plain}
\newcommand\mcitex[2]{\textsuperscript{[}\citealp{#1}%
\textsuperscript{,}\citealp{#2}\textsuperscript{]}}

\usepackage{hyperref,cleveref}
\hypersetup{colorlinks,allcolors=blue} % just for this example
\begin{document}

text\cite{testref1,testref2, testref3, testref4, testref5}

text%
\mcitex{testref1}{testref2, testref3, testref4, testref5}%
\mcitex{testref1, testref2}{testref3, testref4, testref5}%
\mcitex{testref1, testref2, testref3}{testref4, testref5, testref6}

\bibliography{samplebib}
\end{document}


Here, using my prior answer, with changes for your current situation, I did two things:

1. I did not add brackets to the modified \@cite macro, but instead did this: \renewcommand{\@cite}[1]{\textsuperscript{#1}}; and

2. I added the brackets to the \mcite macro directly, as in \newcommand\mcite[1]{$^[$\mcitehelp#1&\relax$^]$}.

Here is the MWE:

\documentclass{article}
\usepackage{cite}
%\usepackage{hyperref,cleveref} % I am using these packages as well
\usepackage{filecontents}
% References
\begin{filecontents}{samplebib.bib}
@article{testref1,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
@article{testref2,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
@article{testref3,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
@article{testref4,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
@article{testref5,
title = {Test title},
journal = {Test Journal},
author = {Test authors and others},
volume = {1},
year = {2016}
}
\end{filecontents}

\makeatletter % Cite references to be in square brackets, superscript
\renewcommand{\@cite}[1]{\textsuperscript{#1}}
\makeatother

% The accepted solution from the original question - Credit to Steven B. Segletes
% \newcommand\mcite[1]{\expandafter\mcitehelp\noexpand#1&\relax} % (Old)
\newcommand\mcite[1]{$^[$\mcitehelp#1&\relax$^]$}  % (Updated Code)
\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}.

But this is unsatisfactory because I'd prefer it to look like:

This is some text that requires citation \textsuperscript{[1,\,2--5]}.

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


• Cool, it seems so obvious when you do it. +1 – Troy Jan 5 '17 at 14:21
• edit: Oh but it does mean that all my other references lose their square brackets.. hmm. – Troy Jan 5 '17 at 14:27
• @Troy Unless you use \mcite exclusively, yes. – Steven B. Segletes Jan 5 '17 at 14:28
• @Troy One could redefine \cite to point to \mcite: \let\svcite\cite \def\mcitehelp#1&#2\relax{\svcite{#1}\ifx\relax#2\relax\else‌​$^,$\mcitehelp#2\relax\fi} \let\cite\mcite – Steven B. Segletes Jan 5 '17 at 14:34