josephwright / biblatex-ieee

A biblatex implementation of the IEEE bibliography style
LaTeX Project Public License v1.3c
47 stars 14 forks source link

Conditionally disable compression of cites #23

Closed koppor closed 3 months ago

koppor commented 8 years ago

The IEEETran package documentation states follows:

One complication in compsoc mode is that the IEEE
Computer Society does not compress, but does sort, adjacent
citation numbers.

On tex.sx I read, that the "style includes code for the compression".

For instance, when inputting following

\documentclass{article}
\usepackage[style=ieee,backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}
\begin{document}
\cite{knuth:ct:b}
\cite{sigfridsson}
\cite{worman}
\cite{nietzsche:historie}
\cite{almendro}
\cite{kowalik}
\cite{loh}
\cite{kowalik,loh,almendro}
\printbibliography
\end{document}

the output is as follows:

[1] [2] [3] [4] [5] [6] [7] [5]–[7]

First, I thought, I would expect

[1] [2] [3] [4] [5] [5] [6] [6] [7] [7]

or even

[1] [2] [3] [4] [5] [6] [7]

The output from the tex.sx example is

[2] [6] [7] [5] [1] [3] [4] [1, 3, 4]

Maybe, that example is artificial.

Is it possible, to turn off the compression somehow?

josephwright commented 8 years ago

The compression is a bit complex (in the core styles this is covered by separate numeric and numeric-comp citations styles), so an option might not work. It's certainly doable to turn it off: the question is whether you also want the square brackets around each number or whether you can just use

\usepackage[bibstyle=ieee,citestyle=numeric]{biblatex}

(this will be sorted but not compressed but won't add brackets around each number).

josephwright commented 8 years ago

I've had a look at this, and I'm pretty sure I've got a solution that doesn't need additional files but only a few tweaks in relevant document preambles

\usepackage[style=ieee,backend=biber,citestyle=numeric]{biblatex}
\DeclareCiteCommand{\cite}
  {\bibopenbracket\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}\bibclosebracket}
\renewcommand*\multicitedelim{\bibclosebracket\addcomma \space\bibopenbracket}

If that sounds OK I'll update the documentation: I'm also going to use this simplified approach for the main settings (the current version is rather complex for what I now suspect is no good reason!).

josephwright commented 8 years ago

There's one thing I'm not clear on here (which affects how best to fix it): how the output of the last citation (\cite{kowalik,loh,almendro}) should look. Single numbers presumably run into text, but multiple numbers without compression will look rather odd unless separated by commas (at least to me). I'm of course happy to do the latter if it's what's required, but want to be sure (I've been doing some tests).

yaoling1997 commented 2 years ago

It works well, thank you for posting this. (@^_^@)

yaoling1997 commented 3 months ago

腾讯官方:您的信件已被成功接收~