Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

equation label #413

Open
AminGholizad opened this issue Nov 15, 2023 · 8 comments
Open

equation label #413

AminGholizad opened this issue Nov 15, 2023 · 8 comments

Comments

@AminGholizad
Copy link

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
Copy link

paul-kelleher commented Nov 15, 2023 via email

@AminGholizad
Copy link
Author

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
Copy link

paul-kelleher commented Nov 16, 2023 via email

@lierdakil
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants