My latex inside doc doesn't appear correctly

Hello everyone,
I am developing a new package https://github.com/AbdelazimHussien/MetaheuristicsAlgorithms.jl
Now, I am trying to display the equation in latex format but it doesn’t work. For example Engineering_F3 show strange appearance

I checked JuMP and follow the same but I don’t know why it doesn’t appear

Any help

AFAIK docstrings with LaTeX should look like this:

@doc raw"""
This is an optimization algorithm.

Objective function:
```math
\xi + \eta^2
```

This is inline math: $\xi$ is positive.
"""
struct Algorithm
end

The main point is that LaTeX code should be surrounded by triple backticks, plus the first triple should be immediately followed by math. I used a raw string literal here to avoid escaping backslashes.

As a side note, many metaheuristics seem to be just particle swarm in disguise: https://www.dei.unipd.it/~fisch/ricop/OR2/Metaheuristics-the%20metaphor%20exposed.pdf.

2 Likes

U mean to put ```math before the matheamtical notation.
Right?

Yes, that is correct. Three backticks + math, then your math, then three backticks again (your code currently has two). This is used for “display” math, like important equations.

Perhaps there are other ways, but this works for me.

1 Like

As a concrete example from your latest commit, I’d write it like this:

@doc raw"""
    Engineering_F3(x::Vector{Float64}) -> Float64

Welded Beam Design Optimization Problem.

Minimizes the cost of a welded beam subject to constraints on shear stress, normal stress, deflection, and geometric properties.

# Objective

```math
\vec{z} = [z_1, z_2, z_3, z_4] = [h, l, t, b] \\
\min_{\vec{z}} f(\vec{z}) = 1.10471 z_1^2 z_2 + 0.04811 z_3 z_4 (14 + z_2)
```

# Constraints
...
"""
function Engineering_F3(x)
 5.0
end
1 Like

You can find the complete documentation on how to use LaTeX at

So besides block environments being

```math
[your math goes here]
```

if also documents that inline math should look like ``[your inline math goes here]``, i.e. with two backticks.

2 Likes