gregorio icon indicating copy to clipboard operation
gregorio copied to clipboard

Errors when compiling from another directory

Open jperon opened this issue 6 years ago • 16 comments

Here's an example: if I am in the /home/user folder, then compile the gabc. tex document that is in /tmp/test: lualatex -shell-escape -output-directory=/tmp/test /tmp/test/gabc.tex

  • if this document contains a command \gregorioscore, I get the error The file gabc-score.gabc does not exist;
  • if it contains a command \gabcsnippet, the message obtained is error: kpse prohibits write to file /tmp/test/gabc.gtmp.

I could of course chdir into the document's folder, but I encounter this problem in trying to develop a filter for pandoc, and pandoc doesn't chdir before calling lualatex.

Here is a MWE to test:

\documentclass{article}
\usepackage[autocompile]{gregoriotex}
\begin{document}
\gabcsnippet{(c4) A(f)ve.(c)}
\gregorioscore{gabc-score}
\end{document}

jperon avatar Dec 04 '17 17:12 jperon

The first error sounds like a conflict between the working and relative file path. GregorioTeX assumes that relative file paths are relative to the working directory and that this is the same as the directory of the file being compiled. I don't know if this assumption can be broken (it depends on how it is linked to the other error).

The second error is a kpathsea error and is thus related to file security. Kpathsea won't let you write to arbitrary directories in order to prevent a malicious document from making unintended changes to your system. We can't change that, but you might be able to disable that security restriction with an option to the luatex call or an appropriate conf file.

✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝ Br. Samuel, OSB (R. Padraic Springuel) PAX ☧ ΧΡΙΣΤΟΣ

On Dec 4, 2017, at 12:00 PM, jperon [email protected] wrote:

Here's an example: if I am in the /home/user folder, then compile the gabc. tex document that is in /tmp/test: lualatex -shell-escape -output-directory=/tmp/test /tmp/test/gabc.tex

if this document contains a command \gregorioscore, I get the error The file gabc-score.gabc does not exist; if it contains a command \gabcsnippet, the message obtained is error: kpse prohibits write to file /tmp/test/gabc.gtmp. I could of course chdir into the document's folder, but I encounter this problem in trying to develop a filter for pandoc, and pandoc doesn't chdir before calling lualatex.

Here is a MWE to test:

\documentclass{article} \usepackage[autocompile]{gregoriotex} \begin{document} \gabcsnippet{(c4) A(f)ve.(c)} \gregorioscore{gabc-score} \end{document} — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

rpspringuel avatar Dec 04 '17 17:12 rpspringuel

I can confirm that, when setting the environment variable openout_any=a, the first error disappears ; the second doesn't with the MWE, but as pandoc "stays" in the original folder, it finds the score. So as is, it works.

Just in case ; wouldn't it be possible to detect when kpse prohibits to write to output-directory, and then default to a subfolder of current directory (that would be writeable) to avoid failing compilation ?

jperon avatar Dec 04 '17 20:12 jperon

I would have expected setting openout_any to eliminate the second error, not the first. My understanding of what is going on my be flawed.

✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝ Br. Samuel, OSB (R. Padraic Springuel) PAX ☧ ΧΡΙΣΤΟΣ

On Dec 4, 2017, at 3:28 PM, jperon [email protected] wrote:

I can confirm that, when setting the environment variable openout_any=a, the first error disappears ; the second doesn't with the MWE, but as pandoc "stays" in the original folder, it finds the score. So as is, it works.

Just in case ; wouldn't it be possible to detect when kpse prohibits to write to output-directory, and then default to a subfolder of current directory (that would be writeable) to avoid failing compilation ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

rpspringuel avatar Dec 04 '17 21:12 rpspringuel

My mistake, excuse me : the second error disappeared, not the first. You understood well !

jperon avatar Dec 04 '17 22:12 jperon

In that case, I think the problem with writing to the CWD when kpathsea finds output-dir to be not writable is that we'd basically be ignoring the output-dir argument, something the user probably won't like (though obviously there are exceptions). Perhaps a suitable error/warning combined with an option to prioritize compilation over respecting the output-dir could overcome this objection.

✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝ Br. Samuel, OSB (R. Padraic Springuel) PAX ☧ ΧΡΙΣΤΟΣ

On Dec 4, 2017, at 5:48 PM, jperon [email protected] wrote:

My mistake, excuse me : the second error disappeared, not the first. You understood well !

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

rpspringuel avatar Dec 05 '17 02:12 rpspringuel

I think so ; on the other hand, shouldn't this behaviour be considered as a Kpathsea bug ? The output directory isn't an arbitrary one, as the user explicitly indicates it as a target. In that case, I could report it upstream (even if I don't know where).

jperon avatar Dec 05 '17 07:12 jperon

Well, if it is a kpathsea or luatex bug the one should be able to reproduce it without using GregorioTeX. I don't have time to dig into this, but if you can reproduce the bug with the underlying file writing functions then I'm happy to help with the upstream reporting.

✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝ Br. Samuel, OSB (R. Padraic Springuel) PAX ☧ ΧΡΙΣΤΟΣ

On Dec 5, 2017, at 2:47 AM, jperon [email protected] wrote:

I think so ; on the other hand, shouldn't this behaviour be considered as a Kpathsea bug ? The output directory isn't an arbitrary one, as the user explicitly indicates it as a target. In that case, I could report it upstream (even if I don't know where).

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

rpspringuel avatar Dec 05 '17 16:12 rpspringuel

The problem doesn't occur while writing directly from lua code.

Now I remember the problem had already occured when \gabcsnippet was introduced, hence PR #494. But since the compilation of gabc scores now makes use of temporary files (.gaux), the process was reverted.

So I think the real problem comes from how gregorio detects wether kpathsea allows writing or not (probably the kpathsea_out_name_ok_silent test in src/support.c line 151). Then the problem would come from source/texk/kpathsea/tex-file.c in luatex source ; but with my knowledge in C, I can't tell anything more…

jperon avatar Dec 05 '17 17:12 jperon

I've come across this error in some of my own work and that has spurred me to think about a possible solution.

One thing I've come up with is the possibility of creating a GregorioTeX specific working directory in a place which kpathsea does permit writing (like the current directory). All gtex and glog files would go into this folder. We could also use it for snippets if we ever implement the feature to keep gtex files for debugging (https://github.com/gregorio-project/gregorio/issues/1206).

Does anyone have any thoughts on this idea?

rpspringuel avatar Dec 13 '18 21:12 rpspringuel

I have found that this is a problem when trying to use the subfiles package.

Nokel81 avatar Mar 04 '20 22:03 Nokel81