5

I am using pandoc to convert a LaTeX document to Word format. The source document contains various cross-references that need to be kept in the output. However, when the cross-references filter is used pandoc complains that it is not installed:

$ pandoc main.tex --filter pandoc-crossref -o main.docx
Error running filter pandoc-crossref:
Could not find executable pandoc-crossref

A package with Python bindings for filters is installed:

$ dpkg -l |  grep pandoc
ii  pandoc                                        2.5-3build2                                         amd64        general markup converter
ii  pandoc-data                                   2.5-3build2                                         all          general markup converter - data files
ii  python3-pandocfilters                         1.4.2-2                                             all          python3 bindings for Pandoc's filters

So I would assume that filters are included in the general pandoc package. It could be that the cross-references filter is somehow missing.

But there are no other filter packages available:

$ aptitude search pandoc | grep filter
p  pandoc-plantuml-filter - Pandoc filter: converts PlantUML code blocks to PlantUML images
i A python3-pandocfilters - python3 bindings for Pandoc's filters
$ aptitude search pandoc | grep cross
$

Is this filter simply not packaged and needs to be manually installed? Or is there some other way of using it on Ubuntu?

2 Answers2

5

This filter is not packaged as standard Ubuntu package.

It is mentioned on https://github.com/jgm/pandoc/wiki/Pandoc-Filters , so you can download and install it from https://github.com/lierdakil/pandoc-crossref manually.

For the reproducible results you have to get both newest pandoc and pandoc-crossref as precompiled binaries using commands below:

cd ~/Downloads
wget -c https://github.com/jgm/pandoc/releases/download/2.13/pandoc-2.13-1-amd64.deb
sudo apt-get install ./pandoc-2.13-1-amd64.deb
sudo apt-get autopurge pandoc-data

wget -c https://github.com/lierdakil/pandoc-crossref/releases/download/v0.3.10.0a/pandoc-crossref-Linux.tar.xz tar -xf pandoc-crossref-Linux.tar.xz sudo mv pandoc-crossref /usr/local/bin/ sudo chmod a+x /usr/local/bin/pandoc-crossref sudo mkdir -p /usr/local/man/man1 sudo mv pandoc-crossref.1 /usr/local/man/man1

Please note that man pandoc-crossref will work.

Then test it with pandoc main.tex --filter pandoc-crossref -o main.docx as you have already planned.


But for more productive results I would recommend to start using bookdown (RMarkdown Markdown extension), it will do all for you in simplified form. Here you can have united Rmd input format and multiple output formats including TeX, PDF, ePub, HTML, docx, odt and so on. Check the https://github.com/rstudio/bookdown-demo repository as a starting point.

N0rbert
  • 103,263
2

This filter can not be obtained from a PPA or any other packaging resource. The safest option is thus to compile the filter in the system, as N0rbert suggests. However, the compilation instructions at the filter repository do not apply to Ubuntu. Those instructions expect the system to have state-of-the-art software, which is usually not the case in a packaged software ecosystem like that offered by Ubuntu. Here are the instructions that got it working on my system.

To compile pandoc-crossref you must install haskell-stack, the toolchain that compiles the filter.

sudo aptitude install haskell-stack

Here is the first tricky bit. The haskell-stack package available from the Universe is really old, dates back to 2018, meaning that there isn't much it can actually do. Luckily the programme can update itself, running the following:

stack upgrade --binary-only

Now the source code can be cloned. However, the right version must be obtained, with a recent one the compilation fails. This is because the pandoc package in the Universe is also old, from 2019, therefore a matching version must be checked out:

cd git
git clone https://github.com/lierdakil/pandoc-crossref.git
cd pandoc-crossref
git checkout v0.3.4.2

And finally the filter can be compiled:

stack install

This will install the compiled filter to ${HOME}/.local/bin which in my case is just fine.

This method was figured out in this thread.