Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Pandoc not include abstract when LaTeX is converted to plain text?

Tags:

pandoc

I have a latex document (example.tex):

\documentclass{article}

\begin{document}

\begin{abstract}
  This does not get exported.
\end{abstract}

But this is fine.

\end{document}

And want to export it to plain text:

pandoc --to=plain example.tex

However, only the body of the document gets exported, the abstract is excluded from the export.

How do I make pandoc export my abstract too?

I believe that this is answered somewhere in the docs, but I just fail to find where for a relatively long time.

like image 296
foki Avatar asked Oct 16 '25 03:10

foki


1 Answers

This is a fun question and goes deeply into the way pandoc represents documents. tldr: abstracts are treated as metadata, which are not included in plain output per default.

Here are the details: pandoc uses a simple document model which is built from the main text plus additional metadata like title and author. We can see this when running pandoc -s -t gfm example.tex, which will output a GitHub Flavored Markdown and include the metadata in a YAML block.

---
abstract: |
  This does not get exported.
---

But this is fine.

The abstract is there, but in the YAML metadata. Whether and how the metadata is included in the output depends on the output format and the template that pandoc uses. Pandoc fills the template with data from the document. One can check the default template that's used by running pandoc -D plain, but there is some magic behind the scenes that adds special variables, so the output is only moderately instructive.

What's important for us is that we can use a custom template to include the abstract:

ABSTRACT
--------

  $abstract$

$body$

Then if we run pandoc with

pandoc -t plain --template=OUR-TEMPLATE.plain example.tex

we get what we want:

ABSTRACT
--------

  This does not get exported.


But this is fine.
like image 89
tarleb Avatar answered Oct 18 '25 05:10

tarleb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!