Keep backslashes in HTML attributes

I am currently using Hugo 0.12.2 and ox-hugo 0.115.1. My workflow is

  1. Create notes in org-roam
  2. Use ox-hugo to publish to Hugo markdown
  3. Build site with Hugo

Issue Description

I have one small issue when it comes to displaying LaTeX inside of a figure caption. I can copy an image and paste it into my org file which will generate a link like this: [[file:Background/2023-07-20_19-12-54_screenshot.png]]. I can also use the #+CAPTION attribute to include a caption specifically for that image.

org file

#+CAPTION: An HMM with 4 states and 2 observation symbols $y_1$ or $y_2$.
[[file:Background/2023-07-20_19-12-54_screenshot.png]]

When I publish this with ox-hugo, the following snippet is generated in a markdown file.

Markdown

{{< figure src="/ox-hugo/2023-07-20_19-12-54_screenshot.png" caption="<span class=\"figure-number\">Figure 1: </span>An HMM with 4 states and 2 observation symbols \\(y\_1\\) or \\(y\_2\\)." >}}

Hugo then generates the following HTML.

HTML

<figure>
<img src="/ox-hugo/2023-07-20_19-12-54_screenshot.png" alt="<span class=&quot;figure-number&quot;>Figure 1: </span>An HMM with 4 states and 2 observation symbols (y_1) or (y_2).">
<figcaption data-pre="Figure " data-post=":">
  <p>
    <span class="figure-number">Figure 1: </span>An HMM with 4 states and 2 observation symbols (y_1) or (y_2).
  </p> 
</figcaption>
</figure>

The issue here is that the backslashes were removed in the HTML version, so MathJax does not convert y_1 and y_2.

There is a workaround with ox-hugo using shortcodes, but I would have to change my images in the original org notes to something like this:

#+begin_export html
{{< latex-caption src="/path/to/image.jpg" alt="Image description" >}}
Caption with LaTeX: $$E = mc^2$$
{{< /latex-caption >}}
#+end_export

This definitely isn’t an option for me as it would mean that the original images couldn’t be displayed in the org document.

Is there a way around this through Hugo?