# Problem with inline math for Literate-generated notebook

**URL:** <https://discourse.julialang.org/t/problem-with-inline-math-for-literate-generated-notebook/60132>\
**Category:** Package Management\
**Tags:** documentation, literate-programming\
**Created:** [April 27, 2021, 10:06pm UTC](https://discourse.julialang.org/t/problem-with-inline-math-for-literate-generated-notebook/60132 "2021-04-27T22:06:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)\
**Post date:** [April 27, 2021, 10:06pm UTC](https://discourse.julialang.org/t/problem-with-inline-math-for-literate-generated-notebook/60132/1 "2021-04-27T22:06:36Z")

</div>

I’m using `Literate` and Documenter to develop documentation for a new package. Everything is going smoothly as far as the generated HTML docs go. The problem is that the inline math isn’t displayed as math in the generated Jupyter notebook. Displayed math is fine, but inline math isn’t processed properly.

Here is a fragment of the `tutorial.jl` file that is input to `Literate`:

````markdown
# ### Steering Choice: Specify Phasing
# Plane wave illumination induces a progressive phase shift from cell to cell of the structure:
# ```math
# V(\vec{r} + m\vec{s}_1 + n\vec{s}_2) = e^{-j(m\psi_1 + n\psi_2)} V(\vec{r})
# ```
# for all integers ``m`` and ``n``, where ``\vec{s}_1`` and ``\vec{s}_2`` 
# are the *lattice vectors* of the 2D periodic structure, and

````

The corresponding portion of the generated notebook looks like this:

![image](https://global.discourse-cdn.com/julialang/original/3X/9/7/97e6462f5b021d2de448c7661c87a6254a73862d.png)

The contents of the markdown notebook cell containing the math is

```markdown
### Steering Choice: Specify Phasing
Plane wave illumination induces a progressive phase shift from cell to cell of the structure:
$$
 V(\vec{r} + m\vec{s}_1 + n\vec{s}_2) = e^{-j(m\psi_1 + n\psi_2)} V(\vec{r})
$$
for all integers ``m`` and ``n``, where ``\vec{s}_1`` and ``\vec{s}_2``
are the *lattice vectors* of the 2D periodic structure, and
``\psi_1`` and ``\psi_2``
are the incremental phase shifts (a pair of real numbers). Specify
the phasings in degrees as a named tuple as in either of the following two examples:

```

so it appears that Literate correctly translated the math fence to double dollar signs but not the double back-quotes to single dollar signs. Looking at the Literate documentation, it appears that I may be able to create a custom post processing filter to do the conversion, but I would expect that capability to be built into Literate.  
My call to convert the Literate input to a notebook is the simplest possible:

```plaintext
Literate.notebook("tutorial.jl")

```

Am I doing something wrong? Any suggestions are very appreciated.

---

<div class="post-metadata">

**Author:** ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)\
**Post date:** [April 28, 2021, 3:27am UTC](https://discourse.julialang.org/t/problem-with-inline-math-for-literate-generated-notebook/60132/2 "2021-04-28T03:27:57Z")

</div>

My current workaround is to use the following preprocessor:

```julia
function notebook_filter(str)
  re = r"(?<!`)``(?!`)" # Two backquotes not preceded by nor followed by another
  replace(str, re => "\$")
end

Literate.notebook(file, preprocess=notebook_filter)

```

This does the trick, but I suspect there’s a way using Literate without this kind of hack.

---

<div class="post-metadata">

**Author:** ![mortenpi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mortenpi/32/158_2.png) [@mortenpi](https://discourse.julialang.org/u/mortenpi)\
**Post date:** [April 28, 2021, 4:54am UTC](https://discourse.julialang.org/t/problem-with-inline-math-for-literate-generated-notebook/60132/3 "2021-04-28T04:54:42Z")

</div>

I use a similar regex preprocessor. I don’t think there is any other way to do this at the moment. There is an open issue for this: [https://github.com/fredrikekre/Literate.jl/issues/116](https://github.com/fredrikekre/Literate.jl/issues/116)

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [March 1, 2022, 8:25pm UTC](https://discourse.julialang.org/t/problem-with-inline-math-for-literate-generated-notebook/60132/4 "2022-03-01T20:25:30Z")

</div>

This has been fixed in [Literate.jl#190](https://github.com/fredrikekre/Literate.jl/pull/190) which is included in [Literate version 2.13.0](https://github.com/fredrikekre/Literate.jl/releases/tag/v2.13.0).
