lierdakil / pandoc-crossref

Pandoc filter for cross-references
https://lierdakil.github.io/pandoc-crossref/
GNU General Public License v2.0
909 stars 73 forks source link

equation label #413

Open AminGholizad opened 7 months ago

AminGholizad commented 7 months ago

I have an equation like this

$$\begin{equation}\begin{aligned}my fancy equation\end{aligned}\end{equation}$${#eq:test}

how ever it renders it like this image

for it to render properly I have to use it like this

$$\begin{equation}\begin{aligned}my fancy equation\end{aligned}\label{eq:test}\end{equation}$$

doing so, the markdown preview gets corrupted which is apparently a known issue mathjax and obsidian as far as I know.

paul-kelleher commented 7 months ago

I don't think you need "\begin{equation}" when you are using Markdown's $$ to specify an equation. So try this:

$$\begin{aligned}my fancy equation\end{aligned}$${#eq:test}

On Wed, Nov 15, 2023 at 3:22 AM Amin Gholizad @.***> wrote:

I have an equation like this

$$\begin{equation}\begin{aligned}my fancy equation\end{aligned}\end{equation}$${#eq:test}

how ever it renders it like this [image: image] https://user-images.githubusercontent.com/39440488/283058675-6a01316d-8661-43ed-8787-c147e9de3f20.png

for it to render properly I have to use it like this

$$\begin{equation}\begin{aligned}my fancy equation\end{aligned}\label{eq:test}\end{equation}$$

doing so, the markdown preview gets corrupted which is apparently a known issue mathjax and obsidian as far as I know.

— Reply to this email directly, view it on GitHub https://github.com/lierdakil/pandoc-crossref/issues/413, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXYRURWANVIITTSAUXSPPX3YESCXBAVCNFSM6AAAAAA7MFH6I2VHI2DSMVQWIX3LMV43ASLTON2WKOZRHE4TIMZXGYYTMNA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

AminGholizad commented 7 months ago

If I do not use equation environment I will get this error Error producing PDF. ! Package amsmath Error: \begin{aligned} allowed only in math mode. See asmsmath package documantation for explanation. Type H <return> for immediate help. I have encountered this before and only solution i could find was using equation.

I don't think you need "\begin{equation}" when you are using Markdown's $$ to specify an equation. So try this: $$\begin{aligned}my fancy equation\end{aligned}$${#eq:test} On Wed, Nov 15, 2023 at 3:22 AM Amin Gholizad @.> wrote: I have an equation like this $$\begin{equation}\begin{aligned}my fancy equation\end{aligned}\end{equation}$${#eq:test} how ever it renders it like this [image: image] https://user-images.githubusercontent.com/39440488/283058675-6a01316d-8661-43ed-8787-c147e9de3f20.png for it to render properly I have to use it like this $$\begin{equation}\begin{aligned}my fancy equation\end{aligned}\label{eq:test}\end{equation}$$ doing so, the markdown preview gets corrupted which is apparently a known issue mathjax and obsidian as far as I know. — Reply to this email directly, view it on GitHub <#413>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXYRURWANVIITTSAUXSPPX3YESCXBAVCNFSM6AAAAAA7MFH6I2VHI2DSMVQWIX3LMV43ASLTON2WKOZRHE4TIMZXGYYTMNA . You are receiving this because you are subscribed to this thread.Message ID: @.>

paul-kelleher commented 7 months ago

I'm not an expert, but so long as you're outputting only to pdf (and not docx, e.g.), I think this should work:

\begin{equation} \begin{aligned} my fancy equation\label{eq:name} \end{aligned} \end{equation}

This is a reference to \eqref{eq:name}

I just tested it and it seems pandoc-crossref seamlessly blends equations/references of the above sort with equations set apart with $$ and cross-referenced with pandoc-crossref's own markdown syntax.

On Thu, Nov 16, 2023 at 2:36 AM Amin Gholizad @.***> wrote:

If I do not use equation environment I will get this error Error producing PDF. ! Package amsmath Error: \begin{aligned} allowed only in math mode. See asmsmath package documantation for explanation. Type H

for immediate help. I have encountered this before and only solution i could find was using equation. I don't think you need "\begin{equation}" when you are using Markdown's $$ to specify an equation. So try this: $$\begin{aligned}my fancy equation\end{aligned}$${#eq:test} … <#m_-200488138766427079_> On Wed, Nov 15, 2023 at 3:22 AM Amin Gholizad *@*.*> wrote: I have an equation like this $$\begin{equation}\begin{aligned}my fancy equation\end{aligned}\end{equation}$${#eq:test} how ever it renders it like this [image: image] https://user-images.githubusercontent.com/39440488/283058675-6a01316d-8661-43ed-8787-c147e9de3f20.png for it to render properly I have to use it like this $$\begin{equation}\begin{aligned}my fancy equation\end{aligned}\label{eq:test}\end{equation}$$ doing so, the markdown preview gets corrupted which is apparently a known issue mathjax and obsidian as far as I know. — Reply to this email directly, view it on GitHub <#413 >, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXYRURWANVIITTSAUXSPPX3YESCXBAVCNFSM6AAAAAA7MFH6I2VHI2DSMVQWIX3LMV43ASLTON2WKOZRHE4TIMZXGYYTMNA . You are receiving this because you are subscribed to this thread.Message ID: @.*> — Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you commented.Message ID: ***@***.***>
lierdakil commented 6 months ago

Can't reproduce. In fact, the version with \begin{equation} fails with a LaTeX error. Here's what I did:

/tmp/test.md:

$$\begin{aligned}my fancy equation\end{aligned}$${#eq:test}

Then run:

pandoc -F pandoc-crossref /tmp/test.md -o /tmp/test.pdf

Results in /tmp/test.pdf looking like this:

image

AminGholizad commented 4 months ago

I forgot to mention that I am using "obsidian-enhancing-export" plugin which adds this lua filter to the mix


return {
    {
        Math = function (elem)
            if elem.text:find("^%s*\\begin{") ~= nil then
                return pandoc.RawInline('tex', elem.text)
            else
                return elem
            end
        end,
    }
}

Can't reproduce. In fact, the version with \begin{equation} fails with a LaTeX error. Here's what I did:

/tmp/test.md:

$$\begin{aligned}my fancy equation\end{aligned}$${#eq:test}

Then run:

pandoc -F pandoc-crossref /tmp/test.md -o /tmp/test.pdf

Results in /tmp/test.pdf looking like this:

image

lierdakil commented 4 months ago

Well, run that filter after pandoc-crossref. It's changing equations to raw TeX, pandoc-crossref doesn't handle raw TeX.

... also, just changing equations to raw TeX sounds like a bad idea, compatibility-wise.

AminGholizad commented 4 months ago

I have several attempts as follows:

$$\begin{equation}\begin{aligned} 
y&=2x
\end{aligned}\end{equation}$${#eq:test}

cmd1: pandoc -F pandoc-crossref /tmp/test.md -o /tmp/test.pdf cmd2: pandoc -F pandoc-crossref --lua-filter=/tmp/pdf.lua" /tmp/test.md -o /tmp/test.pdf

now either commands give the same error

Error producing PDF.
! LaTeX Error: Bad math environment delimiter.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.140 ...t\hypertarget{eq:test}{}{\begin{equation}

so adding lua filter after pandoc-crossref does not do much

then I tried:

$$}\begin{aligned} 
y&=2x
\end{aligned}$${#eq:test}

now both cmd1 and cmd2 work the same and perfectly. image

However not all my equations have a label so

$$}\begin{aligned} 
y&=2x
\end{aligned}$$

with cmd1 does not put a equation number image

the cmd2 gives this error:

Error producing PDF.
! Package amsmath Error: \begin{aligned} allowed only in math mode.

See the amsmath package documentation for explanation.
Type  H <return>  for immediate help.
 ...

l.140 \begin{aligned}
lierdakil commented 4 months ago

There's an option in pandoc-crossref to number all display math, see the docs (the one you want is autoEqnLabels). So if you modify your cmd1 or cmd2 by adding -MautoEqnLabels then your third test should work as you would want, probably.

There's one catch, though, you can't use \begin{equation*} or other fancy environments this way. In a pinch, you can get by with \nonumber to suppress numbers for some equations. If you're targeting latex and only latex, and need fancy environments, perhaps consider just using raw latex code and \refs.