lierdakil / pandoc-crossref

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

Referencing multiline equations? #131

Open SuperFluffy opened 7 years ago

SuperFluffy commented 7 years ago

Is it possible to reference a particular line in a multiline equations, such as created by the align environment? A LaTeX example would be:

\begin{align}
f(x) &= x + a \label{eqn:two} \\
g(x) &= a x \label{eqn:one}
\end{align}

Given the example in the README, it appears I would give a label to the entire block and reference that one instead.

lierdakil commented 7 years ago

To support something like that, pandoc-crossref would have to understand arbitrary LaTeX math. That's wildly out of scope...

lierdakil commented 7 years ago

That said, it's not out of the realm of possibility, but I probably won't have time to do that in the near future.

marfcg commented 7 years ago

Well, on the same topic, when using

$\begin{aligned}
r_r(k) &= \frac{\sum_{j \in A_k} c_{r,j}}{|A_k|}\;, \\
r_c(k) &= \frac{\sum_{j \in A_k} c_{c,j}}{|A_k|}\;, \\
k_{nn}(k) &= \frac{\sum_{j \in A_k} k_j}{|A_k|}\;.
\end{aligned}$ {#eq:ratios}

the systems is not recognizing {#eq:ratios}. It is displaying in the html as text next to the equations and the reference @eq:ratios is broken: cross-ref-align_eq1 cross-ref-align_eq2

While using pandoc-eqnos it worked fine. Now that I moved to pandoc-crossref to be able to insert section referencing as well, this one broke down. It only works with double $$, which is deprecated TeX syntax.

PS: great job putting this package together! Big thanks!

lierdakil commented 7 years ago

@marfcg, the only reason this syntax doesn't work is pandoc-crossref ignores inline math by design. After all, it wouldn't make much sense to have something like this:

in the equation above, $x$ {eq:something} is coordinate vector in the equation above, x (2) is coordinate vector

Here (2) looks like reference, but is actually an accidental number.

I'm not sure what you're referring to wrt deprecated TeX syntax exactly, but Pandoc Markdown makes a distinct difference between $ and $$, and there are virtually no other ways to get display-style math besides $$. Bear in mind, when outputting to LaTeX, pandoc-crossref converts labelled display math to \begin{equation}...\end{equation}.

marfcg commented 7 years ago

Bear in mind, when outputting to LaTeX, pandoc-crossref converts labelled display math to \begin{equation}...\end{equation}.

That nails it. My concern was that $$ would be passed to LaTeX with that same structure, not with the \begin{equation}. That's what I meant by $$ being deprecated. Thanks for the clarification!

DannyQuah commented 2 years ago

Thank you for a fantastic package. My question is a quick follow-on from @marfcg. Since pandoc-crossref converts double-dollar display-style math to \begin{equation}...\end{equation} anyway, I'd thought it would be possible to use:

\begin{equation}
 x^n = y^n + z^n
\end{equation} {#eq:thisEquation}

However, this ends up not labelling the equation for subsequent \eqref reference, but instead produces the text {#eq:thisEquation} in output. (The snippet above works fine replacing the \begin{equation}...\end{equation} pair with doubled-dollar.) It's of course your design choice - and more than acceptable - that "there are virtually no other ways to get display-style math besides the doubled-dollar". My understanding, however, is that the doubled-dollar construct is deprecated in the sense that it is not part of official LaTeX syntax, e.g., https://en.wikibooks.org/wiki/LaTeX/Mathematics

In any case, thank you again for such an awesome piece of work.

lierdakil commented 2 years ago

Pandoc Markdown is not LaTeX. The syntax for display equations in Pandoc Markdown is $$eqn$$. \begin{equation} is treated as raw LaTeX, not as display math (to see why that matters, try converting to HTML). My position is if you only want LaTeX output, there's little reason to not just use LaTeX -- the main advantage Pandoc has over LaTeX is the support for multiple output formats (and it has enough drawbacks to prefer LaTeX if you don't need those)

pykong commented 1 year ago

Is the problem still present, or can the issue at hand be closed?

The markdown below, containing multi-line aligned equations, where each line holds a unique id, is rendered perfectly find, each id is properly resolved.

Tested with:

Markdown

$$\int f(x) \; dx = F(x) + c$${#eq:int_const}

<!-- prettier-ignore-start -->

\begin{align}
  f(x) &= x^2\\
  g(x) &= \frac{1}{x} \label{eq:frac1}\\
  F(x) &= \int^a_b \frac{1}{3}x^3 \label{eq:frac2}
\end{align}

<!-- prettier-ignore-end -->

Full math supported, equation ids resolved: [@eq:frac1], [@eq:frac2].

Is rendered to:

image


lierdakil commented 1 year ago

@pykong that only works with LaTeX because pandoc-crossref translates everything to LaTeX and lets it sort numbering out by itself. Doesn't work with other output formats.

pykong commented 1 year ago

@pykong that only works with LaTeX because pandoc-crossref translates everything to LaTeX and lets it sort numbering out by itself. Doesn't work with other output formats.

Then I may have misunderstood the problem at hand. :-/ Actually the original post in this issue talks about a LaTeX example.

fncokg commented 1 day ago

For those who still need this, try pandoc-tex-numbering.

The filter will parse your LaTeX math codes and try to understand them, therefore multiline equations are supported and you can determine whether to numbering the whole block or line-by-line.

output-page1