pandoc icon indicating copy to clipboard operation
pandoc copied to clipboard

Fix unintended behavior for template search with custom writer

Open jgm opened this issue 3 years ago • 10 comments

As noted in #8135, if the writer is latex-foo-bar.md, the default latex template will be used (-foo-bar.md is stripped off as extensions when doing template search). This is unintended behavior and should be fixed.

jgm avatar Jun 19 '22 18:06 jgm

Is there another way to use a standard template with a custom writer which looks like a legit use case ? If not, should we consider having one before removing this unwanted feature ?

chrisaga avatar Jun 19 '22 19:06 chrisaga

You can specify the template explicitly using --template=default.latex, can't you?

jgm avatar Jun 19 '22 19:06 jgm

Well ... I guess so. I must confess that after all these years, I am still confused by the way Pandoc manages its data files and configuration. Usually you have by order of priority:

  1. User files and conf (.local/share/whatever)
  2. System-wide files and conf (/usr/share/whatever)
  3. Things which are hardcoded in the application

As far as I understand default.latex would be a mix of 2 and 3; i.e. hard-coded and behaving as if it was a file in some /usr/share/pandoc but not customizable system-wide. Well this is another topic to be discussed, or not, elsewhere ...

chrisaga avatar Jun 20 '22 19:06 chrisaga

It is customizable; you can add your own default.latex to the templates subdirectory of the user data directory. And, if your version of pandoc is compiled without the embed_data_files flag, you can also substitute the version in /usr/share/pandoc/templates.

jgm avatar Jun 20 '22 19:06 jgm

Thanks a lot for this. I dont remember seeing anything about /usr/share/pandoc in the doc. I tested to make a /usr/share/pandoc/templates/default.late (late, not latex ;-) ) but Pandoc failed with Could not find data file templates/default.late so I gess Ubuntu packages you provide does have the embed_data_files flag :-(

chrisaga avatar Jun 20 '22 19:06 chrisaga

There still is an issue though !

The unintended behavior you are about to fix has a little brother: the default pdf engine. pandoc -t latex-foo-bar.lua -o sample.pdf sample.md selects pdflatex as the pdf-engine. with -t mylatex-foo-bar.lua it fails with cannot produce pdf output from mylatex-hk-writer.lua

Honestly it works so well that I love it. You are really sure it's unwanted ? :-D

chrisaga avatar Jun 20 '22 19:06 chrisaga

On the pdf issue, see #7898. All you need to do is explicitly specify --pdf-engine=pdflatex

jgm avatar Jun 20 '22 22:06 jgm

Thanks @jgm all this makes me challenge pandoc's behaviors I was relying on.

My point with the pdf thing was to emphasis a probably unintended trick with the filter name similar to the template name one. I suspected that fixing the behavior for template will fix the behavior for pdf engine too, so I didn't open a separate issue.

chrisaga avatar Jun 21 '22 06:06 chrisaga

I'll have to check to see whether the two issues are interwoven in that way. But both should be fixed, I think.

jgm avatar Jun 21 '22 17:06 jgm

See also #8120 for another relevant issue.

jgm avatar Jun 21 '22 17:06 jgm