I'm getting an "undefined control sequence" error when converting from Markdown to ePub to ConTeXt.
I've been doing this for awhile now with Pandoc and no problems, but today I added a term definition in Markdown and it breaks ConTeXt.
I made a very simple example.
This is test.md:
: An apple is a kind of fruit
And then I convert this to an ePub:
pandoc test.md -o test.epub
And then I convert this for use with ConTeXt:
pandoc -f epub -t context -o test.tex test.epub
And then I run ConTeXt:
context --nonstopmode --batchmode test.tex
This results in the "undefined control sequence" error:
tex error > tex error on line 4 in file /Users/me/test.tex: ! Undefined control sequence
l.4 \startdescription
{Apple}
1 \reference[ch001.xhtmlux23section]{}%
2 \section
3
4 >> \startdescription{Apple}
5 An apple is a kind of fruit
6 \stopdescription
7
tex error > tex error on line 6 in file /Users/me/test.tex: ! Undefined control sequence
l.6 \stopdescription
pandoc 2.7.3
You need to use -s to get the ConTeXt preamble. Otherwise you'll just get a fragment.
Also, why are you using an intermediate format instead of just converting md→context? And why stop to run Context manually, why not have Pandoc execute it? Lets of little details get taken care of along the way when you go stroight from your start to finished format directly.
@jgm Thank you for the help! My actual use case is a little more complicated, and I have my own custom styles for ConTeXt. What I needed to do is add this bit:
\definedescription
[description]
[headstyle=bold, style=normal, location=hanging, width=broad, margin=1cm, alternative=hanging]
@alerque This is a simple example, but I'm using an intermediate format because the main file shared among editors is markdown, but the output is ePub and PDF. After I convert the markdown to ePub, I have a shell script that does some image replacement and other things, and then I use Pandoc to convert the finalized ePub into PDF with ConTeXt.
I am running ConTeXt manually because 1) I didn't know you could do that with Pandoc and 2) I have to clean up some of the output produced by Pandoc, again with a shell script.
You can set the output format to PDF and select the pdf engine to ConTeXt. If you need to inject custom code you can either do so with a header include (can be done as an argument to pandoc) or by using a custom template (dump the default one, make your changes, then specify your edited one as the template)
My experience is you are almost certainly better off running your shell script on the _input_ side, not the output. If for some reason that's not appropriate, using a pandoc filter is almost always better than post-processing the output. I don't say this lightly, I have full publishing pipelines set up for an entire publishing company and over the years every time I've implemented something in as a post-processing step I've later ended up realizing it was better to go back and re-implement it as either a pre-processor or a filter.
This is especially true for anything than needs to happen in more than one output format. The only thing left in all my pipelines that chains another format conversion after Pandoc EPUB → MOBI using kindlegen.
@alerque Thank you for the thorough advice. I'm just starting out with this, so it's great to get ideas about how I can improve my process.
I didn't know about the templates; I'll check those out.
Right now, the main bottleneck for turning everything into a filter is that I am better at shell scripting than python, and I don't know any of the other languages that pandoc uses for filters.
@ptmkenny Have a look at https://pandoc.org/lua-filters.html The nice thing about lua filters are that pandoc includes a lua-runtime so they work for all pandoc users out of the box.
Most helpful comment
You can set the output format to PDF and select the pdf engine to ConTeXt. If you need to inject custom code you can either do so with a header include (can be done as an argument to
pandoc) or by using a custom template (dump the default one, make your changes, then specify your edited one as the template)My experience is you are almost certainly better off running your shell script on the _input_ side, not the output. If for some reason that's not appropriate, using a pandoc filter is almost always better than post-processing the output. I don't say this lightly, I have full publishing pipelines set up for an entire publishing company and over the years every time I've implemented something in as a post-processing step I've later ended up realizing it was better to go back and re-implement it as either a pre-processor or a filter.
This is especially true for anything than needs to happen in more than one output format. The only thing left in all my pipelines that chains another format conversion after Pandoc EPUB → MOBI using
kindlegen.