# Enable \write18 for package getmap

Is there a way to enable write18 from the tex file without adding any parameters in the config files ? The idea would be to build this file without modifying anything else but this file.

I sincerely hope it is not possible. If it turns out that it is, that is a serious bug and should be reported and fixed as soon as possible.

The point of restricting writing is to limit the binaries for security reasons e.g. to prevent them writing to, or reading from, files which they ought not write or read to; to limit the potential impact of malicious code; and to constrain the amount of damage which could be done to the system.

It is easy to overstate the dangers here: there are limitations to what might go wrong anyway. But the dangers of unrestricted shell escape are, nonetheless, considerable. With unrestricted shell escape, I can execute arbitrary code and I could destroy anything on my system for which I have write permission. That is a not inconsiderable risk.

Hence, the design of the restrictions is precisely intended to prevent them from being circumvented from with a document. It is a feature and not a limitation.

# EDIT I

This edit consists of two parts. The first part is intended to illustrate some suggestions made in the comments.

If you use Arara to compile the .tex file, then you can control the compilation command from within the file itself. As explained above, once compilation has started, the option to enable write, restricted write or no write cannot be modified. However, what Arara lets you do is work around this by providing a wrapper around the compilation command which can, therefore, be specified in the .tex file.

For example if I want TikZ figures to be compiled separately from PDFs stored in a sub-directory, ffigurau, then I can use the following code to achieve this using Arara and TikZ's external library:

% arara: pdflatex: { shell: true }
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzsetexternalprefix{ffigurau/}
\tikzexternalize
\begin{document}
\tikz{\node {ABC};}
\tikz{\node {XYZ};}
\end{document}


arara <filename> or arara <filename>.tex will then compile the file using pdflatex --shell-escape, as specified on the first line. Arara parses these lines for commands it should run, based on a configuration file and a set of .yaml rule files. See the documentation for details and examples.

# EDIT II

This part is intended to explain why you ought not want what you are asking for.

Let's start with a small demonstration modified from an example on page 2 of bashful's manual:

The original version of this code may permanently delete files from your system, especially if you speak Welsh. The version posted here therefore contains a deliberate error.

\documentclass{article}
\usepackage[a6paper ]{geometry}
\usepackage{bashful}
\pagestyle{empty}
\begin{document}
The directories in my \texttt{/usr} directory are:
\bash[stdout]
printf %b "Initial listing of files in directory:\n"
ls -F ./ffigurau
rm ,/ffigurau/*
printf %b "Current listing of files in directory:\n"
ls -F ./ffigurau
\END
That's it!
\end{document}


Here's the output:

Note that pdflatex has deleted every file in the specified directory. The files are permanently removed from the system. They are not in the Trash or rendered invisible. They are gone.

OK. Let's try something a bit more adventurous. Consider the following listing of files in ../My\ Documents:

drwxr-xr-x  2 username username 4.0K Med   1 02:17 ./


Note that all files in this directory are write-protected: no user, including me, has permission to modify them. If I try to remove my dissertation, for example:

rm ../My\ Documents/my-dissertation.tex
rm: remove write-protected regular file ‘../My Documents/my-dissertation.tex’? n


Normally, rm deletes files without warning. But, in the case of a write-protected file, it is more cautious. Of course, the files are mine, so the protection doesn't prevent me from deleting the files if I wish.

Now suppose I compile the following code, which you've kindly sent me, with Arara:

Note that the actual code permanently deletes the directory My Documents and all its contents, if that directory is one level above the working directory. Since this is potentially extremely destructive, the version posted here contains a deliberate error.

% arara: pdflatex: { shell: true }
\documentclass{article}
\usepackage[a6paper ]{geometry}
\usepackage{bashful}
\pagestyle{empty}
\begin{document}
The directories in my \texttt{/usr} directory are:
\bash[stdout,stderr]
printf %b "Initial listing of files in directory:\n"
ls -F ../My\ Documents
rm -rf ,,/My\ Documents
printf %b "Current listing of files in directory:\n"
ls -F ../My\ Documents
\END
That's it!
\end{document}


Here's the output:

Note that although all files in the directory were protected, rm -rf can still destroy them along with their unprotected parent. Again, these files are permanently deleted. Short of trying disaster recovery tools or turning to backups, my (very short but brilliant) dissertation, the company's (brief but impressive) accounts and my critical (though entirely empty) report are gone.

With shell escape enabled, pdflatex destroys everything. It does this even though the directory in question is above my current working directory - a fact which would normally put it off-limits for any writes by the compiler.

• No hope to locally enable write18 too ? – celli Aug 31 '15 at 3:43
• @celli You can enable it locally by saying e.g. pdflatex --shell-escape: sure. There's no problem with that. You can even do it within the .tex file if you compile with e.g. Arara and add the relevant argument to the line it parses. But, once, compilation starts, the code the engine parses should not be able to alter the setting. [Note: I assume that on public systems, there may be further restrictions on what is possible.] – cfr Aug 31 '15 at 3:46
• Then @cfr, adding % arara: pdflatex: {shell: yes} on the first first line shoud work but I still have the \write 18 error. – celli Aug 31 '15 at 4:01
• @celli Are you running arara <file> or pdflatex <file>? – egreg Aug 31 '15 at 8:28
• @celli As explained, the system is designed to prevent this: it is a feature and, if it failed, it would be a serious bug. Moreover, any user who does NOT ask questions about code they are compiling is ignorant or an idiot or both. And you certainly should not try to circumvent the security features implemented by the software they are using. If I knew that you even thought about wanting to do this, I would not run any of your code on my system under any circumstances, and I would advice others to refuse as well. You ought not want to do this ESPECIALLY not on others' machines. – cfr Sep 1 '15 at 0:31