rjournal / rjtools

Tools for AUTHORS to use for checking and submitting articles to the R Journal
https://rjournal.github.io/rjtools/
Other
31 stars 14 forks source link

Incorrect rendering of labels in equations (LaTeX) #31

Closed pbiecek closed 2 years ago

pbiecek commented 2 years ago

I really like the look of the HTML papers. However, I have a problem with the equations and have not found a good solution.

I have following chunk of code:

\begin{equation} 
STP_{\textit{parity loss}} = \Big | \ln \Big( \frac{STP_b}{STP_a} \Big)\Big|. 
\end{equation} 

This notation is very helpful because it allows to accumulate $STP_{\textit{parity loss}}$ overall unprivileged subgroups, so not only in the binary case.

\begin{equation} 
STP_{\textit{parity loss}} = \sum_{i \in \{a, b, ...\}} \Big|\ln \Big(\frac{STP_i}{STP_a} \Big)\Big|.  
\label{eq:parityLoss}
  (\#eq:parityLoss)
\end{equation} 

Equation \@ref(eq:parityLoss)

I would like to refer to the second equation. In LaTeX I use \label{eq:parityLoss} and in markdown (\#eq:parityLoss).

It renders like that in HTML:

Screenshot 2022-03-07 at 9 55 22 PM

and like that in PDF:

Screenshot 2022-03-07 at 9 55 59 PM

One problem is that in markdown some equations are not numbered, so the numbering of equations differs between HTML and PDF.

The second problem is that in PDF the label (#eq : parityLoss) does not disappear.

I have tried to deal with this by using conditional evaluation of R code chunks, but I have not been able to solve this problem.

Any suggestions are welcome!

huizezhang-sherry commented 2 years ago

The same issue was brought up in #26

pbiecek commented 2 years ago

Hi, the #26 is closed/solved, but the suggested solution is not working for equations

mitchelloharawild commented 2 years ago

The issue with (#eq : parityLoss) showing is due to specifying the label twice.

The correct code for this should be:


\begin{equation} 
STP_{\textit{parity loss}} = \Big | \ln \Big( \frac{STP_b}{STP_a} \Big)\Big|. 
\end{equation} 

This notation is very helpful because it allows to accumulate $STP_{\textit{parity loss}}$ overall unprivileged subgroups, so not only in the binary case.

\begin{equation} 
STP_{\textit{parity loss}} = \sum_{i \in \{a, b, ...\}} \Big|\ln \Big(\frac{STP_i}{STP_a} \Big)\Big|.  
  (\#eq:parityLoss)
\end{equation} 

Equation \@ref(eq:parityLoss)

As for the numbering issue, this is probably trickier to fix.

web: image

pdf: image

mitchelloharawild commented 2 years ago

The temporary quick fix for the inconsistent numbering is of course to always label equations, even if they aren't referred to. I think the fix for numbering equations without labels will need to occur in the bookdown side of the html rendering.

mitchelloharawild commented 2 years ago

It seems that this is the documented behaviour of bookdown: https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#equations

For HTML output, bookdown can only number the equations with labels.

If you don't want to number equations, use an equation* environment. If you want to number equations, use an equation environment and provide the label for it to be numbered. Bookdown does not automatically number equation environments.

mitchelloharawild commented 2 years ago

Closing as this is the documented behaviour of bookdown::html_document2(). Labelling of equations, figures and tables should be done in accordance with the bookdown format.