TransWikia.com

Compressing consecutive footnote marks

TeX - LaTeX Asked by user001 on January 29, 2021

This question led to a new package:
footnoterange

I have a series of consecutively numbered footnotes that appear as (1,2,…,N). I would like these to be condensed to a hyphenated series consisting of only the first and last member of the series (1–N), analogous to the behavior of the cite and natbib packages for consecutively-numbered bibliographic references. I have loaded the package footmisc to enable proper display of consecutive footnotes, but this package appears to only support comma delineation (and not hyphenation) of footnote lists (cf. footmisc manual).

Edit: I have added three MWEs to make my intentions clear. MWE1 shows the default LaTeX behavior. MWE2 shows the improvements afforded by invocation of usepackage[multiple]{footmisc}. MWE3 shows the desired outcome.

MWE1 (default):

enter image description here

MWE2 (footmisc):

enter image description here

MWE3 (desired):

enter image description here

The source codes are included here:

MWE1 (default):

documentclass{article}
usepackage[hmargin=1in,vmargin=4.75in]{geometry}
begin{document}
This text bears a multiplicity of footnotes%
footnote{Lorum}footnote{ipsum}footnote{dolor}%
footnote{sit}footnote{amet,}footnote{consectetur}%
footnote{adipisicing}footnote{elit}.%
end{document}

MWE2 (footmisc):

documentclass{article}
usepackage[hmargin=1in,vmargin=4.75in]{geometry}
usepackage[multiple]{footmisc}
begin{document}
This text bears a multiplicity of footnotes%
footnote{Lorum}footnote{ipsum}footnote{dolor}%
footnote{sit}footnote{amet,}footnote{consectetur}%
footnote{adipisicing}footnote{elit}.%
end{document}

MWE3 (desired):

documentclass{article}
usepackage[hmargin=1in,vmargin=4.75in]{geometry}
begin{document}
This text bears a multiplicity of footnotes$^{1textrm{--}8}.$%
footnotetext[1]{Lorum}footnotetext[2]{ipsum}footnotetext[3]{dolor}%
footnotetext[4]{sit}footnotetext[5]{amet,}footnotetext[6]{consectetur}%
footnotetext[7]{adipisicing}footnotetext[8]{elit}%
end{document}

3 Answers

Starting with version 1.0 (2021/01/21) fnpct supports ranges for multiple footnotes natively¹:

documentclass{article}
usepackage{fnpct}
setfnpct{ranges}
begin{document}
This text bears a multiplicity of footnotes%
footnote{Lorum}footnote{ipsum}footnote{dolor}%
footnote{sit}footnote{amet,}footnote{consectetur}%
footnote{adipisicing}footnote{elit}
 which are referenced as one footnoterange.
end{document}

enter image description here

enter image description here


  1. Credits to Frank for suggesting that feature a while back

Answered by cgnieder on January 29, 2021

If you want to give the references to a range of footnotes, the footnoterange environment of the footnoterange package is the obvious choice:

documentclass{article}
% load hyperref or footmisc or other packages here
% hyperref-option hyperfootnotes=true or =false as you like
% if you use the cleverref package:
%  it must be loaded after hyperref, never before hyperref
usepackage{footnoterange}
begin{document}
This text bears a multiplicity of footnotes%
begin{footnoterange}%
footnote{Lorum}footnote{ipsum}footnote{dolor}%
footnote{sit}footnote{amet,}footnote{consectetur}%
footnote{adipisicing}footnote{elit}%
end{footnoterange}%
 which are referenced as one footnoterange.
end{document}

Use the footnoterange* environment, if you use the hyperref package with option hyperfootnotes=true but without wanting hyperlinked footnotes. [As for a truly automatic solution without the need for begin{footnoterange} and end{footnoterange}: Sorry! That's too tricky. See also Incompatibility between footmisc-option multiple and hyperref asking for more automatic footnote-handling.]

Answered by Stephen on January 29, 2021

I suggest you look into the cleveref package and its commands crefrange and cref. The former commands takes two arguments, the first and last label of a range of items to be cross-referenced; with the second command, you just specify all labels that are to be cross-referenced, and the package will sort and, if possible, compress the list automatically. The arguments of the cref command needn't even be in any order.

The following MWE illustrates how this may be done.

documentclass{article}
usepackage[para]{footmisc} % since you mention that you use this package
usepackage{cleveref}
  newcommandcrefrangeconjunction{--}      % default: " to "
  newcommand{creflastconjunction}{, and } % default: " and ", i.e., without the comma
begin{document}
section{Hey, let's create some footnotes}
Oncefootnote{A label{fn:A}} uponfootnote{B label{fn:B}} afootnote{C label{fn:C}} time,footnote{D label{fn:D}} therefootnote{E label{fn:E}} wasfootnote{F label{fn:F}} ldots

section{Now let's cross-reference these footnotes}   
As is demonstrated in crefrange{fn:A}{fn:F}, ldots

noindent
As additionally noted in cref{fn:F,fn:A,fn:D,fn:E,fn:B}, ldots
end{document}

enter image description here enter image description here

Of course, the cleveref package's cross-referencing commands work not only with footnotes, but with just about all items that can be given a label -- equations, sections, figures, tables, algorithms, and so on.

Finally, be sure to have the latest version of the cleveref package on your system, as the package has recently been updated and upgraded significantly by its author. For instance, the creflastconjunction macro that's used in the MWE probably won't work unless you have a recent version of the package.

Answered by Mico on January 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP