I would like to type F#5, but instead of the pound sign, I'd like to use the actual musical "sharp" symbol (\sharp), which I can access with $\sharp$ in math mode. However, the numeral 5 after the second $ messes with how it's is parsed, so F$sharp$5 renders as F$$5. It only seems to work if I put a space between it, as in F$\sharp$ 5, but that renders as F# 5 and I don't want the space there.
Is there some symbol I can put between the second $ and 5, or some other trick, to ensure that they should be separated? My temporary solution is to put the 5 inside of math mode (F$sharp5$) but I don't like that the 5 is in a different font than the rest of the text.
This is a hack, but ...
If I put \newcommand{\five}{5} immediately after the header at the beginning of my document, I can later use F$\sharp$\five and get no space between the sharp symbol and the 5.
This is just an idea, as I am not sure Pandoc can parse differently, but you could also open an issue about F$\sharp$5 not being parsed as Math with a space after last $
Thank you for your detailed response! I wasn't able to get it to work, but it might be because all this Pandoc code is above my paygrade, so to speak. Maybe I should open an issue because this seems a bit complex for what I believe should be a straightforward fix.
Sorry to hear that (and seeing this just now - sorry for the delay).
The code I shared still works for me using latest versions of R Markdown and RStudio IDE. This is also using a recent Pandoc. You can check the version you are using with rmarkdown::pandoc_version()
But this could just be a parsing limitation for some reason as this is documented in Pandoc's MANUAL (Pandoc - Pandoc User’s Guide)
Anything between two $ characters will be treated as TeX math. The opening $ must have a non-space character immediately to its right, while the closing $ must have a non-space character immediately to its left, and must not be followed immediately by a digit.
Why this rule ? I don't know but when this is documented, I believe this is not an issue.
As you are targetting HTML, why not use the HTML version for the Unicode character ?