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

MDPI issue with equation numbering #326

Closed
3 tasks done
etiennebr opened this issue Sep 25, 2020 · 6 comments
Closed
3 tasks done

MDPI issue with equation numbering #326

etiennebr opened this issue Sep 25, 2020 · 6 comments

Comments

@etiennebr
Copy link

Equation labels are not translated \label{eq:eq} when knitting with mdpi_article, but they are with bookdown::pdf_document2.

Here's the Rmd

This is an equation
\begin{equation}
(\#eq:eq)
c = a \cdot b
\end{equation}
  
see \@ref(eq:eq)

And 
$$
(\#eq:eq2)
a = c \cdot b
$$
  
see \@ref(eq:eq2)

Knit with bookdown::pdf_document2
image

Knit with rticles::mdpi_article
image

It seems like there is some processing not happening. I don't have a deep knowledge of knitr, so I suspect it might simply be that the mdpi_article and pdf2_document are unrelated, and mdpi in fact uses pdf_document for rendering, but in any case, I'd like to reference equations in a mdpi paper, so this might be a feature request. Also, per rstudio/bookdown#190 (comment), it seems like the second equation should also be translated to \begin{equation} ... \end{equation} (at least for ebooks), so I wondered if one of my packages was outdated, but apparently not (see session info below, but knitr_1.30, rmarkdown_2.3, bookdown_0.20, rticles_0.16.1 all seemed fine).

Here are the rendered .tex

With bookdown::pdf_document2 yields in .tex

This is an equation
\begin{equation}
\label{eq:eq}
c = a \cdot b
\end{equation}

see \eqref{eq:eq}

And
\[
\label{eq:eq2}
a = c \cdot b
\]

see \eqref{eq:eq2}

With rticles::mdpi_article, the tex is:

This is an equation \begin{equation}
(\#eq:eq)
c = a \cdot b
\end{equation}

see @ref(eq:eq)

And \[
(\#eq:eq2)
a = c \cdot b
\]

@dleutnant, any idea? @cderv, I'm happy to dive a bit deeper in rticles/knitr if you can point me in a general direction where this could be fixed, or how to have a step-by-step look at the knitting process because I'm completely new to this code.

session info
xfun::session_info('rticles')
#' R version 3.6.3 (2020-02-29)
#' Platform: x86_64-pc-linux-gnu (64-bit)
#' Running under: Ubuntu 18.04.5 LTS, RStudio 1.3.1073
#' 
#' Locale:
#'   LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C               LC_TIME=en_CA.UTF-8       
#'   LC_COLLATE=en_CA.UTF-8     LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8   
#'   LC_PAPER=en_CA.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
#'   LC_TELEPHONE=C             LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       
#' 
#' Package version:
#'   base64enc_0.1.3 digest_0.6.25   evaluate_0.14   glue_1.4.2      graphics_3.6.3 
#'   grDevices_3.6.3 highr_0.8       htmltools_0.5.0 jsonlite_1.7.1  knitr_1.30     
#'   magrittr_1.5    markdown_1.1    methods_3.6.3   mime_0.9        rlang_0.4.7    
#'   rmarkdown_2.3   rticles_0.16.1  stats_3.6.3     stringi_1.5.3   stringr_1.4.0  
#'   tinytex_0.26    tools_3.6.3     utils_3.6.3     xfun_0.17       yaml_2.2.1    

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.name/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('rticles'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/rticles').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@etiennebr
Copy link
Author

Using base_format: rticles::mdpi_article as a base format pretty much resolves the issue

output:
  bookdown::pdf_book: 
    base_format: rticles::mdpi_article

image

But

$$
(\#eq:eq2)
a = c \cdot b
$$

is still rendered to

\[
\label{eq:eq2}
a = c \cdot b
\]

But I guess it's an issue for bookdown, rather than rticles.

@cderv
Copy link
Collaborator

cderv commented Sep 27, 2020

Hi @etiennebr,

this is indeed the official way for now to add bookdown features to any other format. It is document in the book:

we may in the future move the referencing feature in rmarkdown directly to make it available more broadly without doing this.

So you just need to change the output: field in the yaml

it seems like the second equation should also be translated to \begin{equation} ... \end{equation}

Pandoc will not do the conversion. It will transform $$ to the bracketed syntax: https://pandoc.org/MANUAL.html#extension-tex_math_dollars

And it seems for bookdown referencing of equation you need to explicitly use \begin{equation} as described in the documentation https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#equations

It seems $$ works for HTML though - Maybe we could support the $$ syntax for pdf output. This is indeed a bookdown issue.

@cderv
Copy link
Collaborator

cderv commented Sep 27, 2020

Also, bookdown features is to provided same referencing mechanism for different type of output.

With rticles, the output format is only tex for now so I think it is expected that reference mechanism from tex be used directly maybe.

This is an equation
\begin{equation} \label{eq:1}
c = a \cdot b
\end{equation}
  
see \ref{eq:1}

But I can see the advantage of having one syntax, and that the equation preview in rstudio works.

@etiennebr
Copy link
Author

etiennebr commented Sep 27, 2020

@cderv, thanks for all the pointers.

we may in the future move the referencing feature in rmarkdown directly

Is there an issue I can track?

Maybe we could support the $$ syntax for pdf output

Opened #959

@cderv
Copy link
Collaborator

cderv commented Sep 27, 2020

Is there an issue I can track?

Not yet. It is just an idea for now. Nothing yet planned. I am referencing issues that points toward that being a good idea. And testing the idea in the wild ! 😉

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants