Closed friendly closed 3 months ago
This is a MathJax problem. If you add this to the top of the script it will work.
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: { equationNumbers: { autoNumber: "AMS" } }
});
</script>
I see that the markdown fix is easy enough though; \label{eq:myeqn} ->(\#eq:myeqn)
, which I can add to Eqn()
to try and detect the correct output without introducing hacks.
This is the detection approach I'm currently thinking, but I'm not sure how sound it is (what if one is exporting to Word?)
getOutputType <- function(){
type <- 'latex' # for interactive/non-interactive source()
# if(knitr::is_latex_output()) type <- 'latex'
if(knitr::is_html_output()) type <- 'html'
type
}
if(getOutputType() == 'html') print_other_label()
... rmarkdown
drives me crazy sometimes. I couldn't even get this to render in the output.
\begin{equation}
(\#eq:binom)
f\left(k\right) = \binom{n}{k} p^k\left(1-p\right)^{n-k}
\end{equation}
The equation \@ref(eq:binom) ...
and it's because you need
output: bookdown::html_document2
instead of rmarkdown::html_vignette
. So now we're at an impasse; force the bookdown approach whenever the output should be HTML, in which case the equation labels and how they are reference should be changed, or try the MathJaX header configuration for the more generic HTML solution. The latter is more tempting.
I copied
dev/Eqn_test.Rmd
tovignettes/latex-equations.Rmd
to make it into a vignette, using HTML format as is usual.In the YAML header, I have
which is what I've used in other vignettes to give figure numbers that can be cross-referenced. However, for equations, I get no numbers and xrefs don't work. This may be an issue with
bookdown
, but maybe there's something I'm missing.