# Can't insert shortcode parameter without quotation marks

To enable the rendering of equations I need to put the formula into a scripttag that uses type="math/tex" as attribute.

The shortcode is called with

{{% equation "f(x) = \int \frac{2x^2+4x+6}{x-2}" %}}

The shortcode looks like

<script type="math/tex">{{ .Get 0 }}</script>


The output I get:

<p>
<script type="math/tex">"f(x) = \\int \\frac{2x^2+4x+6}{x-2}"</script>
</p>


But the equation can’t be wrapped into quotation marks, otherwise it can’t be interpreted/rendered. If I include the expected output (without quotes)

<script type="math/tex">S_n = a \times \frac{1-r^n}{1-r}</script>


into the shortcode everything works fine.

I already experimented with replace, substring and printf "%s" .Get 0 but none of this approaches turned out to be successful.

A shortcode with .Inner content seems like a better fit for this.

I think this is coming from html/template, not shortcodes. It’s smart enough to detect that you’re printing a variable in a <script> context, and therefore escapes it. It looks like the right way around this is to call template.JS but there’s no safeJS function available in template_funcs.go that would wrap this call.

Sounds like a good feature to add, unless there’s some way to convince html/template not to handle <script type="math/tex"> fields like it handles JavaScript.

@bep I tried with .Inner but it didn’t helped either. Calling the shortcode

<script type="math/tex" >{{ .Inner }}</script>

in my post with

{{% katex %}}S_n = a \times \frac{1-r^n}{1-r}{{% /katex %}}

doesn’t fix it. The output is still:

<p><script type="math/tex" >"S_n = a \\times \\frac{1-r^n}{1-r}"</script></p>.

@dimo414 I did a bit of research and found similar problems on Stackoverflow that required mostly a custom function/filter. This article shows pretty good, that the quotation is added to prevent XSS-attacks and other abuse.

There I would suggest to add a filter named saveJS to Hugo.

Try:

<script type="math/tex" >{{ .Inner | safeHTML }}</script>


I gave it a try, but then I get the following error message:

executing “theme/shortcodes/katex.html” at : wrong type for value; expected string; got template.HTML

Converting .Inner to a string with

<script type="math/tex" >{{ (printf "%s" .Inner) | safeHTML }}</script>

removed the error message, but the equation is still in quotes. It seems, that it would be easier to drop this optional feature for a theme.

I’m having a similar problem. I’m trying to inject a variable into a script to drop markers on a map. Here’s a snippet of the javascript (it’s in a partial):

      {{ range \$.Site.Data.events }}
{{ if eq .status "current" }}
['{{ .city}} ', {{ .coordinates | safeHTML }}],
{{ end }}
{{ end }}
];


The problem is, the output then looks like this:

    var markers = [

['Kiel', "47.609895, -122.330259"],
];


Google Maps requires the coordinates to NOT be in quotation marks. Suggestions?

This may help:

That would definitely help! In our workflow, we’ll probably have to wait until 1.5 is released, since we use wercker to build the site, etc, so we can’t really use dev versions of hugo