formatr-markdownmarkdowndecimal-point

RMarkdown mid-line Decimal Place for Lancet


I'm writing an article for a Lancet Journal, which infuriatingly require the decimal place to be a placed mid-line (ie, 23·4, not 23.4). I typically write my articles in RMarkdown for reproducibility reasons (very easy to track numbers in the code to where they appear in the paper).

Does anyone know a way to tell RMarkdown renders (to a word doc) to use the mid-line · for all decimal places instead of the standard .? I can go through the paper and change them all manually but the whole point of using RMarkdown was to not have to do that kind of thing.


Solution

  • This might be pretty easy using a document hook. That is an R function that is given the output from knitr to process before passing it to Pandoc to convert to Word. The only tricky part is recognizing the difference between decimal points and periods that you don't want to convert.

    I'll assume every number you display that has a decimal point has a digit on either side of it, like 23.4 does, but 23. doesn't, nor does .3. If that's true, you just need to add this code to your document, probably in the setup chunk (but I don't think it really matters where):

    middecimal <- function(s, ...) {
      gsub("([[:digit:]])[.]([[:digit:]])",
           "\\1·\\2", s)
    }
    
    knitr::knit_hooks$set(document = middecimal)
    

    Then you'll end up with a display like this from the demo RMarkdown document, modified to add this:

    enter image description here