Angus Fisk
Angus Fisk

Reputation: 1

Specifying citation format when converting from word to markdown using pandoc

Problem

I am trying to write text in a markdown file, which I then convert to a word file to send to collaborators for comment. I then want to be able to convert the word file back into markdown so I can use git for version control and viewing the changes.

When I convert from word back into markdown, the citation is not preserved and is instead converted to a link instead.

Steps to reproduce

I have my original file

input.md

---
title: "Input file"
bibliography: bibliography.bib
---

# Original text file 

lorum ipsum [@reference], something else. 

and my bibliography file bibliography.bib

@article{reference,
        title = {Some article},
        author = {Me, Someone Else},
        date = {2024-01-01}
        }

I then convert this using pandoc

pandoc input.md -o output.docx --citeproc 

Which produces the output.docx that I want.

    Input file

Original text file

lorum ipsum (Me 2024), something else

Me, Someone Else. 2024. “Some Article,” January.

Then I convert back to markdown using

pandoc output.docx -o new_input.md

Which produces

# Original text file

lorum ipsum (Me 2024), something else

Me, Someone Else. 2024. "Some Article," January.

I want the output to be

# Original text file

lorum ipsum [@reference], something else

Solutions tried

  1. pandoc input-md -o output.docx --citeproc --metadata link-citations=True

When I do this the output makes a link but does not put in the citation key like I want leaving the new_input.md file as:

# Original text file

lorum ipsum ([Me 2024](#ref-reference)), something else

Me, Someone Else. 2024. "Some Article," January.
  1. Creating my own csl file and using that (not confident got this right)
<?xml version="1.0" encoding="UTF-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" version="1.0">
  <info>
    <title>BibTeX Key Only</title>
    <id>https://www.zotero.org/styles/bibtex-key-only</id>
    <updated>2024-12-03T00:00:00+00:00</updated>
    <author>
      <name>Your Name</name>
    </author>
    <category citation-format="author-date"/>
    <summary>A citation style that outputs BibTeX citation keys in Pandoc Markdown format.</summary>
  </info>

  <citation>
    <layout>
      <text variable="citation-label" prefix="[@" suffix="]"/>
    </layout>
  </citation>

  <bibliography>
    <layout>
      <text variable="id"/>
    </layout>
  </bibliography>
</style>

Then running pandoc output.docx -o new_input.md --csl word_to_markdown.csl, but this does not appear to have any effect.

  1. Zotero lua filter I have tried using this zotero lua filter to see if keeping the citations as a citation format in word helps. running pandoc input_md -o output.docx --lua-filter=zotero_filter.lua

When I convert back to markdown from this wihtout running zotero refresh in word it gets the closest to what I want, producing

# Original text file 

lorum ipsum \<Do Zotero Reresh:\[@reference\]\>, something else.

otherwise, if converted back to markdown after running zotero refresh it produces similar output to earlier

# Original text file

lorum ipsum (Me 2024), something else.

Question

How to convert citations in word to markdown as @keys using pandoc?

Version

pandoc version 3.5

Upvotes: 0

Views: 37

Answers (0)

Related Questions