Way to adapt plugin "obsidian-pandoc-reference-list" so it reads LaTeX style citations?

This plugin here renders citations in the sidebar. However, this is only the case if the citation is in the style @citekey.

I’d like to try using this plugin because it’d be neat to have an overview of the sources used in a note, however my workflow uses LaTeX style citations, e.g. \cite{citekey}, and the curly brackets appear to be incompatible with that plugin.

I’m reluctant to try changing that part of my workflow because I’m able to output the PDFs pretty much exactly how I want, so I’d really rather try changing something on the Obsidian side of things.

Does anyone have a suggestion how to have the plugin be able to render these kinds of citations?

Thanks :slight_smile:

Did you test whether using markdown citations instead of Latex citations would affect your PDF output?

Else, it is indeed the “Pandoc Reference List” community plugin that would need to be adapted.

What exactly does this entail? Is that just @citekey? I it is, then yes, it breaks my system, i.e. \cite{@citekey} gets output as @citekey and is useless.

So I just spent over an hour trying to figure this out, but I just don’t know what I’m doing.

If anyone knows how to modify this plugin it would be greatly appreciated!

Can you say more about your workflow, and why you need latex citations in markdown?
Because perhaps you could switch to Pandoc markdown citations, as the Pandoc Reference List plugin expects, and then convert to Latex as needed using Pandoc. Is that not a viable workflow?

I switched to this workflow over a year ago, and I don’t remember what exactly was going wrong with others, I just remember that I couldn’t get stuff to work, e.g. with Pandoc alone.

I don’t actually use \cite{ and instead mainly use \footcite which creates footnotes with citations. And the Pandoc Reference plugin can’t seem to do that (that I’ve seen).

My workflow:
I have a note, with citations à la \footcite{citekey} in them.

"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\footcite[243-246]{Chiang2005What}

then I run a shell command on that note. This is my most favorite plugin ever, it’s so cool to have that integrated into Obsidian.

This is basically just a shell script which looks something like this:

mkdir -p /home/Obsidian/Vault/{{title}}
pandoc  -f markdown-blank_before_blockquote-auto_identifiers -w latex {{file_path:absolute}} -o /home/Obsidian/Vault/{{title}}/{{title}}.tex \
--template=/home/LaTeX/Template/default-template.tex \
[here are some filters that convert Obsidian ==highlighting== to LaTeX highlighting]
gnome-terminal -- bash -c "cd /home/Obsidian/vault/{{title}} && latexmk -pv- -pdflua < /dev/null && latexmk -c && exit; exec bash"

This creates a new folder with the note title in my vault, creates a .tex file from the .md note, and then turns that .tex file into a PDF.

What’s important for this is that it uses a LaTeX template file. And this is where I can really finetune my citations, the formatting of the PDF, precise line spacing, different edge cases of footnotes, and whatever else that might happen.

In the end it looks like this:


image

Initially I had to write my Obsidian note, then convert it to .tex and then go into a LaTeX editor, I used TeXstudio, to finetune and output the PDF. I’m able to skip this step by using a template and just spit out the PDF thanks to the shellcommands plugin.

It’d be neat to be able to have an overview in the sidebar of all the sources I used in a note, which is why I’m looking for an implementation of the pandoc-reference plugin.

Any ideas on how to do this without breaking my system?

Thanks :slight_smile:

This is not to say that you should change your workflow, but just to showcase an alternative approach, as there are some elements of your workflow that could be simplified. For example regarding:

Using Pandoc, you only have to add +mark extension to the --from/-f statement to achieve this. Adding to your command, it becomes:
-f markdown+mark-blank_before_blockquote-auto_identifiers

For a full example utilizing the Shell commands plugin, see below:

pandoc "{{file_path:absolute}}" -f markdown+mark-blank_before_blockquote-auto_identifiers -t pdf -o "{{vault_path}}/{{title}}/{{title}}.pdf" --template=/home/LaTeX/Template/default-template.tex --pdf-engine=lualatex --citeproc --bibliography=/your/bibfile/path.bib --csl=FOOTNOTE_STYLE

Here, you would need to specify the path to your bibliography file (unless already specified in the YAML), and replace FOOTNOTE_STYLE with the path or URL of an appropriate CSL file.

Even though the output format is PDF in this instance, Pandoc still uses latex as the intermediary typesetting format, and you can also instruct Pandoc to use a template just as before.

In this workflow, you would be citing using Pandoc citations, and using a citation style that uses footnotes (for example Chicago or IEEE).

Pandoc Reference List can render the citations as footnotes like ^[1], but it won’t create the footnote reference list at the end of the note, only in the sidebar reference list.

Well, it’s thanks to Pandoc, isn’t it? That’s what is applying the template. But of course, Shell commands is great as it facilitates the execution of these scripts / commands from within Obsidian using variables.

If the above doesn’t suit you, I think you would have to make a feature request on the Pandoc Reference List GitHub repository. But I’m not sure if it would gain traction, as Pandoc citations are the gold standard in markdown, and that’s where the plugin gets its name from.

Edit: You would still need the mkdir part, because Pandoc doesn’t create implied folders, as I thought: Implicitly create directories for output files · Issue #1182 · jgm/pandoc · GitHub

OK, I’m game to try that out, so I added that to your suggestions to a new shellscript but now I’m getting this error:
image

And you’re right! I was forgetting how important pandoc was for this. It’s just been in the background for so long, I forgot all about it haha

My LaTeX template does not have anything like \begin{CSLReferences} and I can’t find a solution on this online. Any ideas?
Thanks :slight_smile:

{CSLReferences} is a required environment in Pandoc’s templates for PDF output (see this), but it is specified like this:
\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing

To see the full expected implementation in context, print the default template that Pandoc uses, when you don’t specify a template, like so:

pandoc -o /output/path/default.tex --print-default-template=latex

replacing /output/path/ with the desired path. Then compare this default template to your current one, and merge them. Usually, people start with the default template and modify it to suit their needs.

OK, so I’ve got it sort of running now, but now I’m struggling with finetuning again.

E.g. the year in the footnote is now printed in parentheses, which I don’t want, i.e. instead of Smith (2020) 25-30 I need Smith 2020, 25-30.

That’s just the first thing. So it seems this method doesn’t entirely use my LaTeX template, though it uses some of it. How would I manage this part?

And another thing is that the bibliography is just printed at the end of the document, and doesn’t get the title that I’ve given it in my LaTeX template:
\printbibliography[title=References]

Thanks!

That’s great! :+1:

Which CSL style are you using?

See:
https://pandoc.org/chunkedhtml-demo/9.5-placement-of-the-bibliography.html

You can use a YAML metadata key called reference-section-title to specific the bibliography title:

---
reference-section-title: References
---

This can be specified in the YAML / properties of the document you are converting, or in a defaults file (recommended). Alternatively, you can also pass it as an argument in the command like so: --metadata reference-section-title="References".

That solves this :slight_smile:
I’m using Chicago 17th edition, author-date

The other big problem is the parentheses in the footnote. Don’t know where it’s getting that.

I believe you are looking for one of the Chicago note & bibliography style variants, not author-date. See: Zotero Style Repository

Or perhaps I misunderstood you, and you are referring to this issue? https://tex.stackexchange.com/a/597119
Which might be solvable with this lua-filter? https://tex.stackexchange.com/a/598582

No, it is author-date, just as a footnote. And the parentheses around the year don’t appear in the CSL example, which is why I’m confused by them appearing in my PDFs.

How are you specifying the CSL? Can you copy-paste your command here?

This is at the end of the pandoc shell command:
--pdf-engine=lualatex --citeproc --bibliography=path/to/Library.bib --csl=path/to/local/chicago-author-date.csl

That looks right. There can sometimes be unexpected differences between pdf-engines. Can you try removing the pdf-engine argument to get the default engine ( pdflatex)? Otherwise, there may be something at play in your template.

Sorry for the delay, didn’t see you replied.

If I remove that argument, I get this error:
image

No worries.

Okay, that’s a no-go then. For your template, you’ll need to use lualatex. You could try the default template, and see if you get a different result regarding the parentheses. This should rule out whether the problem is in your template.

If I remove the template argument, it works again, but the citations still have parentheses around the year, so it’s still not working right.