0

This answer explains, referring to this article, how to export a bibliography from MS Word to a .bib file. The script has been slightly improved here. However, this script does not do much to convert the actual inline citations to LaTeX citations. For instance, let’s apply it to the following sample document:

enter image description here

I get:

enter image description here

This isn’t too bad, actually. The citations have been replaced by the tag names in parentheses. Let’s update the script slightly, specifically by modifying the script from line 773–837 so that each citation output looks something like this:

<xsl:template match="b:Citation/b:Source[b:SourceType = 'Book']"> 
  <html xmlns="http://www.w3.org/TR/REC-html40"> 
    <body> 
        <!-- Defines the output format as (Author, Year)--> 
        <xsl:text>@@@parencite{</xsl:text> 
        <xsl:value-of select="b:Tag"/>
        <xsl:text>}</xsl:text> 
    </body> 
  </html> 
</xsl:template>

Then I get the following instead:

enter image description here

Now after using e.g. pandoc or writer2latex to convert this into LaTeX code, all I have to do is string replace @@@ by \, and I’ll have myself a working BibLaTeX document.

The only problem is that the page number (“p. 223”) from the second citation is gone. How can I get it to output @@@parencite[223]{Johnson22} in this case?

I tried looking at the +8000 line source code of the other citation styles, but they were unfortunately quite complicated. I managed to find the line of code <xsl:value-of select="$pages"/> somewhere, so I tried this:

<xsl:template match="b:Citation/b:Source[b:SourceType = 'Book']"> 
  <html xmlns="http://www.w3.org/TR/REC-html40"> 
    <body> 
        <!-- Defines the output format as (Author, Year)--> 
        <xsl:text>@@@parencite[</xsl:text>
        <xsl:value-of select="$pages"/>     
        <xsl:text>]{</xsl:text> 
        <xsl:value-of select="b:Tag"/>
        <xsl:text>}</xsl:text> 
    </body> 
  </html> 
</xsl:template>

But then MS Word no longer recognized the style, which (according to my brief experience) means that the script is no longer valid.

How can I make this work?

2
  • Your best bet here is not to have Word read any XSL stylesheet and to run the conversion outside of Word using some scripting language like python or perl. You could easily extract the Word document XML from the .docx archive (it's just a ZIP file basically, rename it to .zip to look inside) and then run any XSL transform you want on it without Word messing you about. In your example, $pages is likely a variable defined somewhere earlier in the XSLT and so this likely won't work as is.
    – PLK
    Commented Aug 28, 2022 at 13:37
  • @PLK True, but with this solution, the rest of the Word-to-TeX conversion can be handled by pandoc which is a much better conversion tool than anything I will ever be able to write up myself using Python.
    – Gaussler
    Commented Aug 28, 2022 at 13:58

0

You must log in to answer this question.

Browse other questions tagged .