Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cite and bibitem even with citeproc #9031

Closed
jgm opened this issue Aug 27, 2023 · 13 comments
Closed

Use cite and bibitem even with citeproc #9031

jgm opened this issue Aug 27, 2023 · 13 comments

Comments

@jgm
Copy link
Owner

jgm commented Aug 27, 2023

Here is a way of using the standard \cite and \bibitem machinery for citations, while providing arbitrary text generated by citeproc. (Quoting an earlier comment by @u-fischer):

Note: the empty lines between the bibitems are needed for backref.

\documentclass{article}
\usepackage[backref]{hyperref}

\NewDocumentCommand\citeproctext{}{}
\NewDocumentCommand\citeproc{mm}{%
  \begingroup\def\citeproctext{#2}\cite{#1}\endgroup}
\makeatletter
%no brackets:
 \def\@biblabel#1{}
 \def\@cite#1#2{{#1\if@tempswa , #2\fi}}
\makeatother 
\begin{document}
\section{Introduction}

\citeproc{ref-casey2018}{first arbitrary text}


\section{test}

\citeproc{ref-casey2018}{ibid}

\citeproc{ref-doody2018}{another arbitrary text}

\begin{thebibliography}{99}
\bibitem[\citeproctext]{ref-casey2018} Casey, G. (2018). Text

\bibitem[\citeproctext]{ref-doody2018} Doody, G. (2018). Text

\bibitem[\citeproctext]{other} other
\end{thebibliography}
\end{document}

image

Originally posted by @u-fischer in #9022 (comment)

@jgm
Copy link
Owner Author

jgm commented Aug 27, 2023

For the motivation for this see #9022 (comment)

@jgm
Copy link
Owner Author

jgm commented Aug 27, 2023

citeproc styles specify parameters for the bibliography formatting, too (e.g. hanging indent width, entry spacing). Is there a way to customize these if we use bibitem?

@u-fischer
Copy link

sure, \bibitem[...]{} is only a special \item[...], you can put any list you want around it. E.g. with the enumitem package.

\begin{itemize}[leftmargin=1cm,itemindent=-1cm]
\bibitem[\citeproctext]{ref-casey2018}Casey, G. (2018). Text TextText Text 
    \lipsum[1] 
 \end{itemize}

image

(you naturally need also a heading \section{Bibliography} but I assume that your code is adding it already).

jgm added a commit that referenced this issue Aug 27, 2023
See #9031.

TODO:

- We're getting a double References heading; apparently the bibliography
  environment adds one.
- We've lost the formatting of the references specified by the csl style
  (e.g. hanging indent).
@jgm
Copy link
Owner Author

jgm commented Aug 27, 2023

Some working code in the issue9031 branch.
Still some issues having to do with the formatting of the bibliography.

@jgm
Copy link
Owner Author

jgm commented Aug 27, 2023

What is the {99} for in thebibliography environment?
And is there a way to prevent it from including a References section heading?
(We are including our own and this doubles it.)

@jgm
Copy link
Owner Author

jgm commented Aug 27, 2023

OK, I learned that {99} is text as wide as the widest label.

@jgm
Copy link
Owner Author

jgm commented Aug 27, 2023

In order to avoid the doubled References section heading, we need to replace

\section*{References}\label{references}
\addcontentsline{toc}{section}{References}

with

\phantomsection\label{references}
\addcontentsline{toc}{section}{References}
\renewcommand{\refname}{References}

@u-fischer
Copy link

why don't you use your own list? You don't have to use thebibliography.

@jgm
Copy link
Owner Author

jgm commented Aug 27, 2023

Ah, so \bibitem is important for structure and accessibility, but thebibliography is not?

@u-fischer
Copy link

No thebibliography is not handled in a special way, it is simply tagged as a list. I doubt that this will change.

jgm added a commit that referenced this issue Aug 27, 2023
See #9031 and discussion in #9020. This will give us better
accessibility; when tagging is enabled, the citation can be
linked to the bibliography entry.

This changes some of the details of the layout and the default
template. We now use a special enumitem list for the bibliography
items, instead of the old CSLReferences environment.

Internal links to ids beginning in `ref-` are assumed to be
links to bibliography items, and put inside a `\cite` instead
of `\hyperref`.  This may be a bit fragile, so we should probably
add something to citeproc to more definitely identify citation
links.
@jgm
Copy link
Owner Author

jgm commented Aug 27, 2023

Improved code in issue9031 branch. This fixes the doubled title issue and supports CSL's settings for hanging indent and item spacing.
Here's what we now have in the preamble:

\NewDocumentCommand\citeproctext{}{}
\NewDocumentCommand\citeproc{mm}{%
  \begingroup\def\citeproctext{#2}\cite{#1}\endgroup}
\makeatletter
% avoid brackets around text for \cite:
 \def\@biblabel#1{}
 \def\@cite#1#2{{#1\if@tempswa , #2\fi}}
\makeatother
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newlength{\cslentryspacing}
\setlength{\cslentryspacing}{0em}
\usepackage{enumitem}
\newlist{biblist}{itemize}{1}
\setlist[biblist]{label={},leftmargin=\cslhangindent,itemindent=-1\cslhangindent,itemsep=\cslentryspacing}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{#1\hfill\break}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}

Citations look like

(\citeproc{ref-baghramian:relativism}{Baghramian 2004})

and the bibliography:

\section*{References}\label{references}
\addcontentsline{toc}{section}{References}

\phantomsection\label{refs}
\setlength{\cslentryspacing}{0em}
\begin{biblist}
\bibitem[\citeproctext]{ref-baghramian:relativism}
Baghramian, Maria. 2004. \emph{Relativism}. Oxford: Routledge.

\bibitem[\citeproctext]{ref-baghramian.coliva:relativism}
Baghramian, Maria, and Annalisa Coliva. 2020. \emph{Relativism}. Oxford:
Routledge.

\bibitem[\citeproctext]{ref-perry:thought}
Perry, John. 1986. {``Thought Without Representation.''}
\emph{Proceedings of the Aristotelian Society} 60: 137--66.

\end{biblist}

@jgm
Copy link
Owner Author

jgm commented Aug 27, 2023

Right now we \usepackage{enumitem} twice in the template so we should fix that, though it's harmless.

jgm added a commit that referenced this issue Aug 29, 2023
See #9031 and discussion in #9020. This will give us better
accessibility; when tagging is enabled, the citation can be
linked to the bibliography entry.

This changes some of the details of the layout and the default
template. We now use a special enumitem list for the bibliography
items, instead of the old CSLReferences environment.

Internal links to ids beginning in `ref-` are assumed to be
links to bibliography items, and put inside a `\cite` instead
of `\hyperref`.  This may be a bit fragile, so we should probably
add something to citeproc to more definitely identify citation
links.
@jgm
Copy link
Owner Author

jgm commented Aug 29, 2023

@u-fischer I haven't been able to get pagebackref to work with this setup. What am I missing?
Here's a stripped down test file. I'm adding the option pagebackref in the second line.

% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{pagebackref}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math} % this also loads fontspec
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
  % xetex/luatex font selection
\fi
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage{xcolor}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\NewDocumentCommand\citeproctext{}{}
\NewDocumentCommand\citeproc{mm}{%
  \begingroup\def\citeproctext{#2}\cite{#1}\endgroup}
\makeatletter
% avoid brackets around text for \cite:
 \def\@biblabel#1{}
 \def\@cite#1#2{{#1\if@tempswa , #2\fi}}
\makeatother
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newlength{\cslentryspacing}
\setlength{\cslentryspacing}{0em}
\usepackage{enumitem}
\newlist{biblist}{itemize}{1}
\setlist[biblist]{label={},
  leftmargin=\cslhangindent,
  itemindent=-1\cslhangindent,
  parsep=\parskip,
  itemsep=\cslentryspacing}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{#1\hfill\break}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
  pdftitle={Equal Validity and Disagreement},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}

\title{Equal Validity and Disagreement}
\author{John MacFarlane}
\date{January 15, 2022}

\begin{document}
\maketitle

\ldots
Like Baghramian's earlier book of the same title
(\citeproc{ref-baghramian:relativism}{Baghramian 2004}), it aims to be a
comprehensive critical survey, but unlike the earlier book it engages
extensively with the large literature on relativism that emerged in the
first two decades of this century. \ldots

\section*{References}\label{references}
\addcontentsline{toc}{section}{References}

\phantomsection\label{refs}
\setlength{\cslentryspacing}{0em}

\begin{biblist}
\bibitem[\citeproctext]{ref-baghramian:relativism}
Baghramian, Maria. 2004. \emph{Relativism}. Oxford: Routledge.

\end{biblist}
\end{document}

jgm added a commit that referenced this issue Aug 29, 2023
See #9031 and discussion in #9020. This will give us better
accessibility; when tagging is enabled, the citation can be
linked to the bibliography entry.

This changes some of the details of the layout and the default
template. We now use a special enumitem list for the bibliography
items, instead of the old CSLReferences environment.

Internal links to ids beginning in `ref-` are assumed to be
links to bibliography items, and put inside a `\cite` instead
of `\hyperref`.  This may be a bit fragile, so we should probably
add something to citeproc to more definitely identify citation
links.
jgm added a commit that referenced this issue Aug 29, 2023
See #9031 and discussion in #9020. This will give us better
accessibility; when tagging is enabled, the citation can be
linked to the bibliography entry.

This changes some of the details of the layout and the default
template. We now make CSLReferences a special enumitem list
that will contain `\bibitem`s.

Internal links inside citations to ids beginning in `ref-` are
put inside a `\cite` instead of `\hyperref`.
@jgm jgm closed this as completed in 353177f Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants