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:
I get:
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:
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?
.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.