jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.58k stars 3.38k forks source link

Pandoc handling TEXINPUTS differently from pdflatex #8392

Closed dbitouze closed 2 years ago

dbitouze commented 2 years ago

Explain the problem. pandoc seems to no longer support LaTeX's \input, as shown by the following commands:

printf '%s' '\documentclass{article}\begin{document}\input{child}\end{document}' > parent.tex
printf '%s' 'Foo' > child.tex
pdflatex parent
xdg-open parent.pdf
pandoc -o parent.md parent.tex

the last one returning:

[WARNING] Could not load include file child.tex at parent.tex line 1 column 53

and the parent.md file being empty.

Pandoc version?

$ pandoc -v
pandoc 2.19.2
Compiled with pandoc-types 1.22.2.1, texmath 0.12.5.2, skylighting 0.13,
citeproc 0.8.0.1, ipynb 0.2, hslua 2.2.1
Scripting engine: Lua 5.4
User data directory: /home/bitouze/.local/share/pandoc
Copyright (C) 2006-2022 John MacFarlane. Web:  https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

I'm running a Mageia 8 GNU/Linux box.

jgm commented 2 years ago

I can't reproduce this. Here's what I'm seeing with 2.19.2:

% pandoc parent.tex -t markdown
Foo
jgm commented 2 years ago

Tried with both release and dev version, on macos and linux.

dbitouze commented 2 years ago

Quite strange! Here is what I'm seeing:

$ pandoc parent.tex -t markdown
[WARNING] Could not load include file child.tex at parent.tex line 1 column 53

$
dbitouze commented 2 years ago

Just to be sure:

$ cat parent.tex && cat child.tex
\documentclass{article}\begin{document}\input{child}\end{document}
Foo
$ pandoc parent.tex -t markdown
[WARNING] Could not load include file child.tex at parent.tex line 1 column 53

$ pandoc -v                                                                                    
pandoc 2.19.2
Compiled with pandoc-types 1.22.2.1, texmath 0.12.5.2, skylighting 0.13,
citeproc 0.8.0.1, ipynb 0.2, hslua 2.2.1
Scripting engine: Lua 5.4
User data directory: /home/bitouze/.local/share/pandoc
Copyright (C) 2006-2022 John MacFarlane. Web:  https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.
jgm commented 2 years ago
% cat parent.tex && cat child.tex
\documentclass{article}\begin{document}\input{child}\end{document}
Foo
% /usr/local/bin/pandoc parent.tex 
<p>Foo</p>
% /usr/local/bin/pandoc --version  
pandoc 2.19.2
Compiled with pandoc-types 1.22.2.1, texmath 0.12.5.2, skylighting 0.13,
citeproc 0.8.0.1, ipynb 0.2, hslua 2.2.1
Scripting engine: Lua 5.4
User data directory: /Users/jgm/.local/share/pandoc
Copyright (C) 2006-2022 John MacFarlane. Web:  https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.
dbitouze commented 2 years ago

Sigh... From the beginning (Mageia 8 doesn't provide pandoc):

$ cd
$ mkdir temp
$ cd temp
$ wget -q https://github.com/jgm/pandoc/releases/download/2.19.2/pandoc-2.19.2-linux-amd64.tar.gz
$ tar xfz pandoc-2.19.2-linux-amd64.tar.gz
$ cd pandoc-2.19.2/bin
$ printf '%s' '\documentclass{article}\begin{document}\input{child}\end{document}' > parent.tex
$ printf '%s' 'Foo' > child.tex
$ ./pandoc parent.tex
[WARNING] Could not load include file child.tex at parent.tex line 1 column 53

$
jgm commented 2 years ago

I tried that exact sequence of commands on my debian box, and got

<p>Foo</p>

So, I don't know what is happening on your machine. This is strange indeed.

dbitouze commented 2 years ago

Runs smoothly with a Docker image. Would be nice to fix this issue though...

jgm commented 2 years ago

I'd like to fix it too, but we need some diagnosis of where the problem lies. Since I can't reproduce it, we're at a dead end unless you can supply more relevant information. I haven't seen any other reports like this. Is there something different about Mageia linux that might be relevant?

You could try compiling pandoc from source.

dbitouze commented 2 years ago

Compiling pandoc from source looks very difficult on Mageia. I asked for help on the Mageia bug tracker where, since a long time, the lack of pandoc was deplored.

jgm commented 2 years ago

Let me know if they have any ideas. Otherwise we may need to close this as a dead end.

jgm commented 2 years ago

Looking at the code, I have an idea. Is the TEXINPUTS environment variable set on your system, and if so to what?

echo $TEXINPUTS
jgm commented 2 years ago

Another useful test would be to try a restructured text document with an include. a.rst

.. include:: b.rst

b.rst

Hello
pandoc a.rst -t markdown

This would tell us if the issue is tex-specific.

dbitouze commented 2 years ago

Looking at the code, I have an idea. Is the TEXINPUTS environment variable set on your system, and if so to what?

Yes, indeed:

$ echo $TEXINPUTS
~/Images//:

[...] This would tell us if the issue is tex-specific.

Seems to be the case:

$ echo ".. include:: b.rst" > a.rst
$ echo "Hello" > b.rst
$ pandoc a.rst -t markdown
Hello
jgm commented 2 years ago

OK! Then that's your issue. You have TEXINPUTS set up to look only in the Images directory. Try

export TEXINPUTS=$HOME/Images/:.

and that should add the working directory . to the list of directories pandoc will search.

jgm commented 2 years ago

Reopening because I can see we're not handling TEXINPUTS quite right (the latex build succeeded).

dbitouze commented 2 years ago

Reopening because I can see we're not handling TEXINPUTS quite right (the latex build succeeded).

Indeed: the extra dot in export TEXINPUTS=$HOME/Images/:. makes a mess in LaTeX which makes all compilations fail :smile:.

jgm commented 2 years ago

Right, I think you always want a colon at the end -- this tells tex to use its default directories -- and the dot should go at the beginning.

export TEXINPUTS=.:$HOME/Images//:

In the commit above, I've fixed pandoc so that it will no longer require the dot, but this should get you going for now.