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

Support native citations in docx #7889

Open
agusmba opened this issue Feb 3, 2022 · 3 comments
Open

Support native citations in docx #7889

agusmba opened this issue Feb 3, 2022 · 3 comments

Comments

@agusmba
Copy link
Contributor

agusmba commented Feb 3, 2022

Similar to #7886, #7875 and #7840, but related to native citation/bibliography support already present in Word (docx).

It would be nice if pandoc coud both read and write using docx's native support for citations.

I'll update this with info on the XML parts involved

relevant additions to document.xml (long text)
<w:r w:rsidRPr="00FA6B19">
        <w:rPr>
          <w:lang w:val="en-GB"/>
        </w:rPr>
        <w:t>Sample file to demonstrate native c</w:t>
      </w:r>
      <w:r>
        <w:rPr>
          <w:lang w:val="en-GB"/>
        </w:rPr>
        <w:t>itation with docx/Word</w:t>
      </w:r>
      <w:sdt>
        <w:sdtPr>
          <w:rPr>
            <w:lang w:val="en-GB"/>
          </w:rPr>
          <w:id w:val="141786920"/>
          <w:citation/>
        </w:sdtPr>
        <w:sdtContent>
          <w:r w:rsidR="0054542B">
            <w:rPr>
              <w:lang w:val="en-GB"/>
            </w:rPr>
            <w:fldChar w:fldCharType="begin"/>
          </w:r>
          <w:r w:rsidR="0054542B" w:rsidRPr="0054542B">
            <w:rPr>
              <w:lang w:val="en-GB"/>
            </w:rPr>
            <w:instrText xml:space="preserve"> CITATION Exa22 \l 3082 </w:instrText>
          </w:r>
          <w:r w:rsidR="0054542B">
            <w:rPr>
              <w:lang w:val="en-GB"/>
            </w:rPr>
            <w:fldChar w:fldCharType="separate"/>
          </w:r>
          <w:r w:rsidR="0054542B">
            <w:rPr>
              <w:noProof/>
              <w:lang w:val="en-GB"/>
            </w:rPr>
            <w:t xml:space="preserve"> </w:t>
          </w:r>
          <w:r w:rsidR="0054542B" w:rsidRPr="0054542B">
            <w:rPr>
              <w:noProof/>
              <w:lang w:val="en-GB"/>
            </w:rPr>
            <w:t>[1]</w:t>
          </w:r>
          <w:r w:rsidR="0054542B">
            <w:rPr>
              <w:lang w:val="en-GB"/>
            </w:rPr>
            <w:fldChar w:fldCharType="end"/>
          </w:r>
        </w:sdtContent>
      </w:sdt>
      <w:r>
        <w:rPr>
          <w:lang w:val="en-GB"/>
        </w:rPr>
        <w:t>.</w:t>
      </w:r>
    </w:p>
    <w:p w14:paraId="48C4A947" w14:textId="73C51BA1" w:rsidR="0054542B" w:rsidRDefault="0054542B">
      <w:pPr>
        <w:rPr>
          <w:lang w:val="en-GB"/>
        </w:rPr>
      </w:pPr>
      <w:r>
        <w:rPr>
          <w:lang w:val="en-GB"/>
        </w:rPr>
        <w:t>A second reference</w:t>
      </w:r>
      <w:sdt>
        <w:sdtPr>
          <w:rPr>
            <w:lang w:val="en-GB"/>
          </w:rPr>
          <w:id w:val="876506361"/>
          <w:citation/>
        </w:sdtPr>
        <w:sdtContent>
          <w:r>
            <w:rPr>
              <w:lang w:val="en-GB"/>
            </w:rPr>
            <w:fldChar w:fldCharType="begin"/>
          </w:r>
          <w:r>
            <w:instrText xml:space="preserve"> CITATION Boo22 \l 3082 </w:instrText>
          </w:r>
          <w:r>
            <w:rPr>
              <w:lang w:val="en-GB"/>
            </w:rPr>
            <w:fldChar w:fldCharType="separate"/>
          </w:r>
          <w:r>
            <w:rPr>
              <w:noProof/>
            </w:rPr>
            <w:t xml:space="preserve"> </w:t>
          </w:r>
          <w:r w:rsidRPr="0054542B">
            <w:rPr>
              <w:noProof/>
            </w:rPr>
            <w:t>[2]</w:t>
          </w:r>
          <w:r>
            <w:rPr>
              <w:lang w:val="en-GB"/>
            </w:rPr>
            <w:fldChar w:fldCharType="end"/>
          </w:r>
        </w:sdtContent>
      </w:sdt>
    </w:p>
    <w:sdt>
      <w:sdtPr>
        <w:id w:val="-1157219546"/>
        <w:docPartObj>
          <w:docPartGallery w:val="Bibliographies"/>
          <w:docPartUnique/>
        </w:docPartObj>
      </w:sdtPr>
      <w:sdtEndPr>
        <w:rPr>
          <w:rFonts w:asciiTheme="minorHAnsi" w:eastAsiaTheme="minorHAnsi" w:hAnsiTheme="minorHAnsi" w:cstheme="minorBidi"/>
          <w:color w:val="auto"/>
          <w:sz w:val="22"/>
          <w:szCs w:val="22"/>
        </w:rPr>
      </w:sdtEndPr>
      <w:sdtContent>
        <w:p w14:paraId="7EA662A7" w14:textId="7F438CF5" w:rsidR="0054542B" w:rsidRDefault="0054542B">
          <w:pPr>
            <w:pStyle w:val="Heading1"/>
          </w:pPr>
          <w:proofErr w:type="spellStart"/>
          <w:r>
            <w:t>Bibliography</w:t>
          </w:r>
          <w:proofErr w:type="spellEnd"/>
        </w:p>
        <w:sdt>
          <w:sdtPr>
            <w:id w:val="111145805"/>
            <w:bibliography/>
          </w:sdtPr>
          <w:sdtContent>
            <w:p w14:paraId="0EDBCA8E" w14:textId="77777777" w:rsidR="0054542B" w:rsidRDefault="0054542B">
              <w:pPr>
                <w:rPr>
                  <w:noProof/>
                </w:rPr>
              </w:pPr>
              <w:r>
                <w:fldChar w:fldCharType="begin"/>
              </w:r>
              <w:r>
                <w:instrText xml:space="preserve"> BIBLIOGRAPHY </w:instrText>
              </w:r>
              <w:r>
                <w:fldChar w:fldCharType="separate"/>
              </w:r>
            </w:p>
            <w:tbl>
              <w:tblPr>
                <w:tblW w:w="5000" w:type="pct"/>
                <w:tblCellSpacing w:w="15" w:type="dxa"/>
                <w:tblCellMar>
                  <w:top w:w="15" w:type="dxa"/>
                  <w:left w:w="15" w:type="dxa"/>
                  <w:bottom w:w="15" w:type="dxa"/>
                  <w:right w:w="15" w:type="dxa"/>
                </w:tblCellMar>
                <w:tblLook w:val="04A0" w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="1"/>
              </w:tblPr>
              <w:tblGrid>
                <w:gridCol w:w="322"/>
                <w:gridCol w:w="8182"/>
              </w:tblGrid>
              <w:tr w:rsidR="0054542B" w14:paraId="1BEE1D64" w14:textId="77777777">
                <w:trPr>
                  <w:divId w:val="2141799766"/>
                  <w:tblCellSpacing w:w="15" w:type="dxa"/>
                </w:trPr>
                <w:tc>
                  <w:tcPr>
                    <w:tcW w:w="50" w:type="pct"/>
                    <w:hideMark/>
                  </w:tcPr>
                  <w:p w14:paraId="20B73523" w14:textId="505603C7" w:rsidR="0054542B" w:rsidRDefault="0054542B">
                    <w:pPr>
                      <w:pStyle w:val="Bibliography"/>
                      <w:rPr>
                        <w:noProof/>
                        <w:sz w:val="24"/>
                        <w:szCs w:val="24"/>
                      </w:rPr>
                    </w:pPr>
                    <w:r>
                      <w:rPr>
                        <w:noProof/>
                      </w:rPr>
                      <w:t xml:space="preserve">[1] </w:t>
                    </w:r>
                  </w:p>
                </w:tc>
                <w:tc>
                  <w:tcPr>
                    <w:tcW w:w="0" w:type="auto"/>
                    <w:hideMark/>
                  </w:tcPr>
                  <w:p w14:paraId="2F7E50CA" w14:textId="77777777" w:rsidR="0054542B" w:rsidRDefault="0054542B">
                    <w:pPr>
                      <w:pStyle w:val="Bibliography"/>
                      <w:rPr>
                        <w:noProof/>
                      </w:rPr>
                    </w:pPr>
                    <w:r w:rsidRPr="0054542B">
                      <w:rPr>
                        <w:noProof/>
                        <w:lang w:val="en-GB"/>
                      </w:rPr>
                      <w:t xml:space="preserve">E. author, «Name of the reference,» 31 1 2022. </w:t>
                    </w:r>
                    <w:r>
                      <w:rPr>
                        <w:noProof/>
                      </w:rPr>
                      <w:t>[En línea]. Available: https://www.example.com.</w:t>
                    </w:r>
                  </w:p>
                </w:tc>
              </w:tr>
              <w:tr w:rsidR="0054542B" w:rsidRPr="0054542B" w14:paraId="7DC11F74" w14:textId="77777777">
                <w:trPr>
                  <w:divId w:val="2141799766"/>
                  <w:tblCellSpacing w:w="15" w:type="dxa"/>
                </w:trPr>
                <w:tc>
                  <w:tcPr>
                    <w:tcW w:w="50" w:type="pct"/>
                    <w:hideMark/>
                  </w:tcPr>
                  <w:p w14:paraId="18EA4E29" w14:textId="77777777" w:rsidR="0054542B" w:rsidRDefault="0054542B">
                    <w:pPr>
                      <w:pStyle w:val="Bibliography"/>
                      <w:rPr>
                        <w:noProof/>
                      </w:rPr>
                    </w:pPr>
                    <w:r>
                      <w:rPr>
                        <w:noProof/>
                      </w:rPr>
                      <w:t xml:space="preserve">[2] </w:t>
                    </w:r>
                  </w:p>
                </w:tc>
                <w:tc>
                  <w:tcPr>
                    <w:tcW w:w="0" w:type="auto"/>
                    <w:hideMark/>
                  </w:tcPr>
                  <w:p w14:paraId="6FC543A6" w14:textId="77777777" w:rsidR="0054542B" w:rsidRPr="0054542B" w:rsidRDefault="0054542B">
                    <w:pPr>
                      <w:pStyle w:val="Bibliography"/>
                      <w:rPr>
                        <w:noProof/>
                        <w:lang w:val="en-GB"/>
                      </w:rPr>
                    </w:pPr>
                    <w:r w:rsidRPr="0054542B">
                      <w:rPr>
                        <w:noProof/>
                        <w:lang w:val="en-GB"/>
                      </w:rPr>
                      <w:t xml:space="preserve">B. author, Book title, Atlantis: Lost City, 2022. </w:t>
                    </w:r>
                  </w:p>
                </w:tc>
              </w:tr>
            </w:tbl>
            <w:p w14:paraId="74E0918F" w14:textId="77777777" w:rsidR="0054542B" w:rsidRPr="0054542B" w:rsidRDefault="0054542B">
              <w:pPr>
                <w:divId w:val="2141799766"/>
                <w:rPr>
                  <w:rFonts w:eastAsia="Times New Roman"/>
                  <w:noProof/>
                  <w:lang w:val="en-GB"/>
                </w:rPr>
              </w:pPr>
            </w:p>
            <w:p w14:paraId="50239960" w14:textId="0571F152" w:rsidR="0054542B" w:rsidRDefault="0054542B">
              <w:r>
                <w:rPr>
                  <w:b/>
                  <w:bCs/>
                  <w:noProof/>
                </w:rPr>
                <w:fldChar w:fldCharType="end"/>
              </w:r>
            </w:p>

There are also references in [Content_Types].xml

In document.xml.rels

In styles.xml

  <w:style w:type="paragraph" w:styleId="Bibliography">
    <w:name w:val="Bibliography"/>
    <w:basedOn w:val="Normal"/>
    <w:next w:val="Normal"/>
    <w:uiPriority w:val="37"/>
    <w:unhideWhenUsed/>
    <w:rsid w:val="0054542B"/>
  </w:style>

In webSettings.xml a bunch of ids (the file was mostly empty before using citations)

New file in customXml/item1.xml (long text)
<?xml version="1.0" standalone="no"?>
<b:Sources xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" SelectedStyle="\IEEE2006OfficeOnline.xsl" StyleName="IEEE" Version="2006">
  <b:Source>
    <b:Tag>Exa22</b:Tag>
    <b:SourceType>DocumentFromInternetSite</b:SourceType>
    <b:Guid>{85BC4F8D-91C0-444D-B378-E4A48878B53E}</b:Guid>
    <b:Author>
      <b:Author>
        <b:NameList>
          <b:Person>
            <b:Last>author</b:Last>
            <b:First>Example</b:First>
          </b:Person>
        </b:NameList>
      </b:Author>
    </b:Author>
    <b:Title>Name of the reference</b:Title>
    <b:Year>2022</b:Year>
    <b:Month>1</b:Month>
    <b:Day>31</b:Day>
    <b:URL>https://www.example.com</b:URL>
    <b:RefOrder>1</b:RefOrder>
  </b:Source>
  <b:Source>
    <b:Tag>Boo22</b:Tag>
    <b:SourceType>Book</b:SourceType>
    <b:Guid>{39AEE514-A3E0-45BD-A372-E8FAF3B04D71}</b:Guid>
    <b:Title>Book title</b:Title>
    <b:Year>2022</b:Year>
    <b:Author>
      <b:Author>
        <b:NameList>
          <b:Person>
            <b:Last>author</b:Last>
            <b:First>Book</b:First>
          </b:Person>
        </b:NameList>
      </b:Author>
    </b:Author>
    <b:City>Atlantis</b:City>
    <b:Publisher>Lost City</b:Publisher>
    <b:RefOrder>2</b:RefOrder>
  </b:Source>
</b:Sources>

New file customXml/itemProps1.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ds:datastoreItem ds:itemID="{5D4D6755-6A11-4FB3-A355-55FD8D503966}" xmlns:ds="http://schemas.openxmlformats.org/officeDocument/2006/customXml">
  <ds:schemaRefs>
    <ds:schemaRef ds:uri="http://schemas.openxmlformats.org/officeDocument/2006/bibliography"/>
  </ds:schemaRefs>
</ds:datastoreItem>

and customXml/_rels/item1.xml.rels

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps" Target="itemProps1.xml"/>
</Relationships>

The sample file: pandoc_7889_ref.docx

Thanks!

@jgm
Copy link
Owner

jgm commented Feb 5, 2022

It would be nice to have a link to documentation for the XML format in
customXml/item1.xml

@agusmba
Copy link
Contributor Author

agusmba commented Feb 7, 2022

It would be nice to have a link to documentation for the XML format in customXml/item1.xml

The xsd can be found here, but documentation itself... is a bit harder to find. Ok, I found some:

I also saw this comparison to Bibtex fields, which might be useful (no xml details though)

@jgm
Copy link
Owner

jgm commented Feb 7, 2022

Thanks. This one will be trickier to support than the others, because of the new XML format and because it is scattered across several files...

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