rr-markdownxaringan

How to properly write dollar sign on xaringan?


I am using Xaringan slides. I want to write dollar values like $10-$5=$5 using math notation.

My code is the following:

$ \$10-\$5 = \$5 $.

However, the code will not generate the outcome in mathematical way as I wanted.

I know it works with double dollar sign $$, but I want to the result stay on the same line.

Also I don't want to put USD or CAD instead of $. Any tip?


Solution

  • Instead of using \$ just define a macro using latex syntax \newcommand

    ---
    output: xaringan::moon_reader
    ---
    
    # Defining inline math expression  containing currency dollar sign
    
    <!---- This is a macro for Mathjax ----->
    $$\newcommand\dollars{\$}$$
    <!---- --------------------------- ----->
    
    This line conttain inline expression $\dollars10 - \dollars5 = \dollars5$
    

    which looks like,

    xaringan_with_dollar_sign_in_inline_Math_Equation