Questions tagged [shell-escape]

{shell-escape} is about the “--shell-escape” argument, i.e. to enable external running of commands from inside the ‘.tex’ file.

If enabled, {shell-escape} mode allows the use of a list of commands which can be specified using \write18{commandlist} in a .tex document. The command \write is a TeX primitive used to write to different streams. The use of stream 18 means that TeX is asking the operating system to do something. The use of \write18{} is usually disabled for security reasons. It must be enabled explicitly using latex --shell-escape texfile.

324 questions
93
votes
3 answers

What are \immediate & \write18 and how does one use them?

What are \immediate and \write18 and how does one use them? I'd like some examples spanning from basic to advanced scenarios.
Display Name
  • 46,933
27
votes
5 answers

How can I save shell output to a variable in LaTeX?

I need to be able to execute a shell command through LaTeX [*] and have the resulting output available for use later on in the form of a LaTeX 'variable' (e.g., via a subsequent \newcommand command). If necessary a temporary file could be used to…
Frank
18
votes
2 answers

How do you detect restricted write18 support

I know about \ifeof18 and \pdfshellescape to detect, if \write18 is enabled, but both only tell me, if it's enabled at all. I need to use a program which isn't in the list of commands restricted \write18is allowed to use and thus want to check, if…
Max
  • 5,702
12
votes
3 answers

Get return value of `\write18`

I'm using \immediate\write18{./somescript.sh} to execute my own shell script at the beginning of the latex compilation process. Is there a possibility to get the return value afterwards?
crateane
  • 2,217
9
votes
1 answer

How to do shell-escape in TeXWorks?

I know this question has been asked a lot of times, however I can't seem to fix my problem. My problem is as follows, I am using MikTex 2.9 and TeXWorks and I try to add the --enable-write18 to enable shell-escape however the output gives: texify:…
Snowflake
  • 755
  • 7
  • 13
6
votes
1 answer

How to invoke \write18{pdflatex "\def\param{...}\input{filename}"}?

Why can't I compile the following even though I have enabled -shell-escape? \documentclass{article} \usepackage{filecontents} \begin{filecontents*}{inputfile.tex} %\def\paramA{standalone} \def\paramB{Hello…
6
votes
1 answer

Problem with writing the output of kpsewhich to a file

I create in my folder a file "blub.temp" and then tried out the following \documentclass{article} \usepackage[T1]{fontenc} \usepackage{shellesc} %correct small bug in shellesc: \protected\def\ShellEscape{\immediate\write18…
Ulrike Fischer
  • 327,261
5
votes
1 answer

How to change the shell used by \write18?

I'm on macOS (the same happens on Ubuntu). Here is my default/current shell: $ ps -p $$ PID TTY TIME CMD 5835 ttys002 0:00.13 -bash Then, here is my document foo.tex: \documentclass{article} \begin{document} \immediate\write18{ps -p…
yegor256
  • 12,021
5
votes
1 answer

How to output a new line in a .txt file with \immediate\write18

I am trying to create a text file foobar.txt using \immediate\write18, and can not figure out how to properly get the \n so that Unix puts these lines on a new line. The MWE below produces one line in the output file: \n \n ---------\n Foo: foo…
Peter Grill
  • 223,288
5
votes
2 answers

Timing response of externally called commands via write18: blocking or not?

I was wondering: when we use \immediate\write18{...} to run commands in an external shell from Latex, is the \write18 a blocking call or not? In other words, will it wait for the external code to complete and return (with success, or not) - or will…
sdaau
  • 17,079
5
votes
1 answer

How to adapt a batch-script / write18-call to Linux systems

I want to compile a bunch of (independent) documents from a main.tex file. The documents are in subfolders and as they can load input files and graphics from other subfolders I need to change the current directory. I think this can't be done inside…
Ulrike Fischer
  • 327,261
4
votes
2 answers

Escaping backslash within \@@input or \write18

Problem I want to include a word count in my document, using texcount. But I also want to include a comma as a thousand separator. This is the code I came up with: \makeatletter\@@input|"echo `texcount -1 -sum=1,1,1,1,1,1,1 -merge -incbib -utf8…
4
votes
2 answers

copy finalised PDF to new directory

I want to automatically make a copy of the finalised PDF in a new directory once it is compiled. As part of my workflow, each article (of my thesis) (and the associated graphics) is stored in its own directory. I then import each file into a master…
James
  • 173
4
votes
1 answer

Toggle permission to use shell escape in document itself

Permitting LaTeX to execute shell code (aka -enable-write-18) is dangerous. But I sometimes need it due to dot2texi. So in my IDE (which in my case is WinEdt) I manually switch it on when I work with dot2texi, and switch it off when when I do not…
3
votes
1 answer

how to escape special chars in \write18?

This is what I'm trying to do (it's just an example, not a real code): \immediate\write18{echo "price: $5.00" > temp.tex} \input{temp.tex} This is what I see in temp.tex: price: .00 What is a possible workaround?
yegor256
  • 12,021
1
2 3