jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.8k stars 3.39k forks source link

support for additional citation packages for md --> tex #3811

Open mkoohafkan opened 7 years ago

mkoohafkan commented 7 years ago

Pandoc currently supports natbib and biblatex for LaTeX output, but no other citation methods, including the default \cite command. It would be great to see Pandoc provide flexible support for citation packages, such as the cite package. This functionality would be useful for e.g. generating tex files for journals that restrict use of natbib or biblatex.

It may be possible to use pandoc variables to support virtually any citation package. My understanding is that Pandoc markdown supports two types of citations: parenthetical [@citation] and textual @citation (difference is the []). Perhaps Pandoc could use two variables for LaTeX templates, e.g. $citeparen$ and $citetext$, which allow users to specify what LaTeX commands to use. So current functionality for natbib in the YAML header would look like:

citation-package: natbib
  - citeparen: citep
  - citetext: citet

and biblatex would (I think?) look like:

citation-package: biblatex
  - citeparen: autocite
  - citetext: autocite

Pandoc would use those variables to populate the .tex file. A third variable $citepackageoptions$ could also be added to allow users to specify options in [], e.g. \usepackage[$citepackageoptions$]{$citation-package$}.

It would of course be up to the user to correctly specify which commands to use. A possible complication arises with citations like [e.g. @citation; see also @another] but again, it's up to the user if they want to use a package with more restrictive functionality than what pandoc provides (then again, pandoc seems to do fine with ignoring the extra text when I use a superscript-based bibliography format with natbib, so maybe not a difficult issue after all).

jgm commented 7 years ago

It's not that simple. There are many differences between natbib and biblatex besides which package to use and which citation commands to use. (E.g. what command to use for the bibliography, and where this command goes.) Note also that with biblatex a variety of commands is used, not just two.

Why not just use pandoc-citeproc and an appropriate csl file that fits your journal's standards?

mkoohafkan commented 7 years ago

Well, mainly because the journal expects a .tex file for submission that uses their template... so they expect the \cite commands rather than plain text citations. Some publishers have the same template but a \journal{} to format the document different according to where it ends up getting published, including bibliography styles. The use case I'm talking about is md --> tex, not md --> pdf.

What about just adding support for base LaTeX \cite commands? Flexible support for arbitrary citation packages may be unrealistic, but support for basic LaTeX citation commands is probably worthwhile.

mkoohafkan commented 7 years ago

Learning more about filters...that's probably the way to go for supporting arbitrary LaTeX citation packages. User could select the citation package closest to the one they actually want to use (e.g. natbib or biblatex) and then use a filter to reformat citations into the actual style of the intended package. I still think it would be valuable to support base LaTeX citations in this case to provide maximum flexibility.

jgm commented 7 years ago

Using pandoc-citeproc you can produce a tex file, but the formatting might not be exactly as the journal expects, if they use bibtex.

As for supporting base LaTeX citations: I can't recall the details of \cite, but is there a way to distinguish author-in-text and normal citations? Is there a way to add prefixes and suffixes, including locators, to the citations?

mkoohafkan commented 7 years ago

Prefixes, suffixes and locators are supported with [] as with natbib. It does not distinguish between parenthetical and in-text citations (just one command: \cite), but neither does natbib when using numeric citations (\citet won't be correctly displayed).

argenos commented 3 years ago

Sorry for reviving an old issue, let me know if a separate issue would be best to track this. I just happen to have run into this today while trying to set up a template to use with markdown -> LaTeX. My case is similar to #2392, where the conference template still uses BiBTeX's \cite (see here). I've resorted to using Ctrl + F and substituting \autocite with \cite, but it would be great if this was instead customizable through the command line or YAML front matter.

jgm commented 3 years ago

I'm open to adding a --bibtex option (parallel to --biblatex, --natbib). But how would it work? We need to support three citation styles, SuppressAuthor, AuthorInText, and NormalCitation, as well as prefixes and suffixes. Can you confirm that standard bibtex \cite allows optional prefixes and suffixes with square brackets? Would we simply not distinguish between the three citation styles?

argenos commented 3 years ago

I have to say that I don't know enough about the internals of BiBTeX/pandoc to know if there's a way to do that. In my field, that's usually not needed (since my citations are always numeric), but based on this the only thing that is possible is to specify details for the locator using \cite[p.~215]{citation01}.

After an extremely quick search on the BiBTeX docs there might be two options (keep in mind that I don't know how hard/problematic this is to implement):

amzon-ex commented 1 year ago

Hi! This requirement fits my use case too - many journals require a tex file and that too with normal \cite commands. Has there been any progress on this?

Also, are there any filters available that could serve the purpose?

jgm commented 1 year ago

You could just add this to the top of your file (untested):

\def\citep\cite
iandol commented 1 year ago

You could just add this to the top of your file (untested):

\def\citep\cite

This didn't work for my use case: trying to get Pandoc output to work with an up-to-date Tufte-latex (using BibLaTeX with this update: https://github.com/Tufte-LaTeX/tufte-latex/pull/176). Tufte-latex looks for \cite to convert to margin placements, and so \autocite fails. However in this case, a solution is this option in the preamble:

\ExecuteBibliographyOptions{autocite=footnote}

This puts \autocite citations into the margin for Tufte-latex...

juandpinto commented 7 months ago

Would love to have a built-in option for the native \cite command. I've managed to write a Lua filter that works decently, but it's not a very robust solution due to all the issues that have already been mentioned in this thread.