Search code examples
r-markdownpandocpapaja

Cross reference equation in RMarkdown knitting to docx (papaja)


I am trying to get equation numbers when knitting my .Rmd to .docx but I haven't found a way to get this or the labels to cross reference them to work. I tried this:

    $$
    P(L|C_L, C_R) = \frac {10^{\sum_{n=1}^ {4} (w_{c_{L,i}} - w_{c_{R,i}})}} {1+10^{\sum_{n=1}^ {4} (w_{c_{L,i}} - w_{c_{R,i}})}}
    $$\label(#eq:left)

The probability for the left side winning can be calculated using \@ref(eq:left)

Which returns this:

enter image description here

Referencing correctly to the equation but the label for it doesn't show (having a (1) on the left or right of the equation) and instead, it prints out the text in the code.

Does anyone know what am I writing wrong here or if this is even possible to do for .docx files?

Thanks for your help


Solution

  • papaja extends bookdown, so the general approach you are trying is correct, but the syntax is a little off. Try the following:

    \begin{equation}
    P(L|C_L, C_R) = \frac {10^{\sum_{n=1}^ {4} (w_{c_{L,i}} - w_{c_{R,i}})}} {1+10^{\sum_{n=1}^ {4} (w_{c_{L,i}} - w_{c_{R,i}})}} 
    (\#eq:left)
    \end{equation}
    
    The probability for the left side winning can be calculated using \@ref(eq:left)
    

    Note that equation references are not well supported in Word (i.e., apa6_docx()). See the here for details.