Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ifplatform: filename escaping issue? #12

Open
Arinerron opened this issue Sep 18, 2023 · 3 comments
Open

ifplatform: filename escaping issue? #12

Arinerron opened this issue Sep 18, 2023 · 3 comments

Comments

@Arinerron
Copy link

Arinerron commented Sep 18, 2023

Unfortunately I can't share reproduction steps, but thought I'd note there seems to be some kind of argument escaping issue:

Rc files read:
  NONE
Latexmk: Run number 1 of rule 'xelatex'
This is XeTeX, Version 3.141592653-2.6-0.999993 (TeX Live 2022/dev/Debian) (preloaded format=xelatex)
 \write18 enabled.
entering extended mode
uname: extra operand 'REDACTED'
Try 'uname --help' for more information.
system returned with code 256
Latexmk: Log file says no output from latex
Latexmk: For rule 'xelatex', no output was made
Collected error summary (may duplicate other messages):
  xelatex: Command for 'xelatex' gave return code 1
      Refer to 'REDACTED.log' for details
Latexmk: Use the -f option to force complete processing,
runsystem(uname -s > ""REDACTED".w18")...executed.


/usr/share/texlive/texmf-dist/tex/latex/ifplatform/ifplatform.sty:92: Package catchfile Error: File `"REDACTED".w18' not found.

See the catchfile package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.92     \CatchFileDef\@tempa{\ip@file}{}

The "REDACTED" filename has spaces in it which probably has something to do with it. I never experienced this issue till I added "-shell-escape" arg to latexmk in our build process.

@muzimuzhi
Copy link

muzimuzhi commented Sep 18, 2023

When the input filename has spaces, like spaces in filename.tex, \jobname is already quoted ("spaces in filename"). But in various places ifplatform adds another pair of quotes. This resulted in executing commands with extra operand, like in

runsystem(uname -s > ""REDACTED".w18")...executed.

\edef\ip@file{\jobname.w18}

\ShellEscape{uname -s > "\ip@file"}

You can use expl3 functions \sys_if_platform_unix:TF and \sys_if_platform_windows:TF to replace ifplatform, also see #5.

If ifplatform is loaded by another package, like minted, here's an emulation of \ifwindows needed by minted.

\documentclass{article}
\ExplSyntaxOn
% pretend ifplatform is loaded
\tl_const:cn {ver@ifplatform.sty} {0000-00-00}
\newif\ifwindows
\sys_if_platform_windows:TF {\windowstrue} {\windowsfalse}
\ExplSyntaxOff
\usepackage{minted}

\begin{document}
\begin{minted}{tex}
  $a + b = c^2$
\end{minted}
content

@jameshbailie
Copy link

Thank you @muzimuzhi I had the same error and your workaround fixed it!

@user202729
Copy link

@wspr Consider fixing this issue? On Linux, this patch fixes it for me:

--- ifplatform.sty      2024-03-04 04:45:05.830042206 +0700
+++ /usr/share/texmf-dist/tex/latex/ifplatform/ifplatform.sty   2024-03-04 04:46:58.536711651 +0700
@@ -51,17 +51,17 @@
 \else
   \IfFileExists{nul:}{\@ip@nix@false}{\@ip@nix@true}
   \IfFileExists{/dev/null}{\windowsfalse}{\windowstrue}
-  \edef\ip@windows@echo@test{echo \string# > "\ip@file"}
+  \edef\ip@windows@echo@test{echo \string# > \ip@file}
   \def\ip@backupplan{%
     \IfFileExists{\ip@file}{%
       \PackageWarningNoLine{ifplatform}{^^J \space\space\space
-        Please delete the file "\ip@file" and try again%
+        Please delete the file \ip@file and try again%
       }%
       \ip@cantdecide
     }{%
       \ShellEscape{\ip@windows@echo@test}%
       \IfFileExists{\ip@file}{%
-        \ShellEscape{del "\ip@file"}%
+        \ShellEscape{del \ip@file}%
         \windowstrue
       }{%
         \@ip@nix@true
@@ -88,9 +88,9 @@
 \def\ip@only@six#1#2#3#4#5#6#7\@nil{#1#2#3#4#5#6}
 \if@ip@nix@\ifshellescape
   \ifwindows\else
-    \ShellEscape{uname -s > "\ip@file"}
+    \ShellEscape{uname -s > \ip@file}
     \CatchFileDef\@tempa{\ip@file}{}
-    \ShellEscape{rm -- "\ip@file"}
+    \ShellEscape{rm -- \ip@file}
     \edef\@tempa{\expandafter\zap@space\@tempa\@empty}
     \def\@tempb{Linux}
     \ifx\@tempa\@tempb

Assume \jobname is also quoted on Windows and Mac etc. if it has a space, this should be safe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants