# Escaping unkown user input to LaTeX

**URL:** https://discourse.julialang.org/t/escaping-unkown-user-input-to-latex/26583
**Category:** Offtopic
**Tags:** question, strings, latex
**Created:** [July 20, 2019, 1:16pm UTC](https://discourse.julialang.org/t/escaping-unkown-user-input-to-latex/26583 "2019-07-20T13:16:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [July 20, 2019, 1:16pm UTC](https://discourse.julialang.org/t/escaping-unkown-user-input-to-latex/26583/1 "2019-07-20T13:16:10Z")

</div>

I’m using `PGFPlotsX` and `LaTeXTabulars` to generate `PDF` reports which include (amongst other things) string comments (user-input via some beyond-my-control GUI) that might contain any of these characters:

```julia
"""!@#$%^&*()_-+={[}]|\"':;?/>.<,~`""" # I basically went through the keyboard with/out pressing SHIFT

```

I need to be able to insert these comments without `LaTeX` crashing or misinterpreting them in math-mode. I honestly don’t care about how the text will look like (in terms of typography), I just want it to work. I thought about surrounding everything with

```julia
"\\detokenize{$x}"

```

where `x` contains the suspicious string, but I hear [that might not cover all cases](https://tex.stackexchange.com/a/289126/12370)?

Is there a way to fix this

1. from Julia?
2. or if you know, from LaTeX? I couldn’t find anything definitive, but I imagined that warpping every such string in some protective environment might do?

Thanks in advance!

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [July 20, 2019, 2:44pm UTC](https://discourse.julialang.org/t/escaping-unkown-user-input-to-latex/26583/2 "2019-07-20T14:44:17Z")

</div>

You can define a simple function in Julia that escapes all LaTeX reserved chars, which I think are

```nohighlight
# $ % ^ & _ { } ~ \

```

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [July 20, 2019, 2:48pm UTC](https://discourse.julialang.org/t/escaping-unkown-user-input-to-latex/26583/3 "2019-07-20T14:48:39Z")

</div>

Awesome, simple and works. Thanks.
