With --shell-escape
:
(because of some permission issue this does not work on Overleaf, but otherwise should work on most POSIX systems)
\ExplSyntaxOn
\sys_get_shell:nnN {ps~-o~args=~-p~$(ps~-o~ppid=~-p~$$)} {\cctab_select:N \c_other_cctab} \l_data_tl
\ExplSyntaxOff
Quoted from my other answer in https://tex.stackexchange.com/a/621510/250119.
Then you need to parse the arguments somehow -- but be warned that parsing the arguments correctly is really difficult.
A simple way is
\str_if_in:VnTF \l_data_tl {-8} {
\typeout{>> probably~8bit}
} {
\typeout{>> not~8bit}
}
but it's not foolproof, I run this simple bash file:
g(){
echo "========" "$@"
"$@" </dev/null | grep '>>\|!'
}
f(){
g pdflatex --shell-escape "$@"
g xelatex --shell-escape "$@"
}
mkdir -p -- --8bit a "a a" # create auxiliary directories named literally "--8bit" and "a" and "a a"
ln -rsf a.tex "a --8bit b.tex" # link "a.tex" -> a file literally named "a --8bit b.tex"
ln -rsf a.tex "b.tex"
# ======== these 3 cases return false:
f a.tex
f --output-di a "a --8bit b.tex"
f --output-di --8bit a.tex
# ======== these 7 cases return true:
f --output-di "a a" --8bit b.tex
f -8bit a.tex
f -8b a.tex
f --8bit a.tex
f --8bi a.tex
f --8b a.tex
f --8 a.tex
f -8 a.tex
with a.tex
contains:
% ======== copy from egreg's test ========
\input catchfile.sty
\newif\ifeightbit
\begingroup
\immediate\openout15=tab.tst
\catcode`\^^?=12
\immediate\write15{^^?}
\immediate\closeout15
\CatchFileDef\atab{tab.tst}{\catcode`\^=12 \catcode`?=12 }
\edef\btab{\string^\string^\string ? }
\ifx\atab\btab
\global\eightbitfalse
\else
\global\eightbittrue
\fi
\endgroup
\ExplSyntaxOn
\cs_generate_variant:Nn \str_if_in:nnTF {V}
\sys_get_shell:nnN {ps~-o~args=~-p~$(ps~-o~ppid=~-p~$$)} {\cctab_select:N \c_other_cctab} \l_data_tl
\typeout{>> \l_data_tl}
\str_if_in:VnTF \l_data_tl {-8} {
\typeout{>> probably~8bit}
} {
\typeout{>> not~8bit}
}
\typeout{>> ifeightbit=\meaning\ifeightbit}
\ExplSyntaxOff
\stop
As you can see, the simple test outputs "probably 8bit" for the last 2 cases of the first block
even though it isn't 8bit.
In particular, the 2nd and 4nd case makes the output identical with the provided command-line argument
(you can fix this by not using ps -o args
but I'm not sure how...)
With LuaLaTeX there's the arg
table, but it looks like you'll still have to manually parse it:
\directlua{for _, v in ipairs(arg) do print(v) end}
\stop
From the other question in In Luatex, how to know effective output directory?.
But... in this specific case LuaTeX always ignore --8bit
argument anyway: