tlienart / PkgPage.jl

Create a beautiful landing page for your package in less than 10 minutes.
https://tlienart.github.io/PkgPage.jl/
MIT License
116 stars 6 forks source link

Math in figure captions #48

Closed adigitoleo closed 2 years ago

adigitoleo commented 2 years ago

I landed here because my half-baked attempts at a figure env for franklin did not turn out. But I want to put math in the figure caption. No can do at the moment because of a parse error, relevant bit:

caused by: Base.Meta.ParseError("invalid interpolation syntax: \"\$\\\"")

Caused by https://github.com/tlienart/PkgPage.jl/blob/master/src/latex/basic.jl#L36-L39

Not sure of the best way to tackle it, maybe build the string incrementally instead of interpolating? Alternative math-mode syntax also fails, because julia turns \( into \\(. Adding more \ doesn't help.

adigitoleo commented 2 years ago

My bad, this is actually coming from lxargs usage in L27. (Although the interpolation later would also suffer this problem.)

tlienart commented 2 years ago

This works:

\begin{center}
  \figure{
    path="/assets/nice_image.jpg",
    width="100%", style="border-radius:5px;",
    caption=raw"Panoramic view of the Tara Cathedrals \(x\) (taken from Wikimedia)."
}
\end{center}

note the raw and the \( and \) instead of the $. This is because this string is directly passed as an HTML string. The raw avoids having to escape the \.

There's now an explicit example of this in the docs (https://tlienart.github.io/PkgPage.jl/#commands)

The fd2html could be called to process caption as a md string and output HTML so that you could do the same with $x$ but this raises an error I wasn't immediately able to trace down and I don't have a lot of time rn to look into it, so for now the workaround above should hopefully be sufficient.

adigitoleo commented 2 years ago

For now I actually ended up with a pure Franklin.jl way:

In config.md:

\newenvironment{figure}{~~~<figure>~~~}{~~~</figure>~~~}
\newcommand{\img}[2]{~~~<img src="!#2" id="!#1" alt="!#1"/>~~~}
\newcommand{\figcaption}[1]{~~~<figcaption>~~~#1~~~</figcaption>~~~}

Now I can do:

\begin{figure}
\img{alt_text}{/path/to/image.png}
\figcaption{Test that can contain math, $x \in \LaTeX$.}
\end{figure}

I loose the ability to style the figure layout directly, but for most cases I can wrap it in a div macro or create a few alternate environments like \figquarter, \fighalf etc.

I am preferring this approach to keep my dependencies minimal, but for people using this package directly your previous solution works as well.