How to include hash tags in a Rmd document so they render correctly in a markdown (.md) document

I am using RStudio and RMarkdown to prepare markdown documents (.md files).

I would like to include hash tags (#tags) within the text of my document.

Rendering my RMarkdown document turns #tag to \#tag in the .md file.

Is it possible for the text #tag to be rendered without the escape backslash? Thanks.

#tag and \#tag also render as \#tag

To which markdown flavour are you rendering to ? Which output format function are you using ?

I think it is expected that a # is escaped in Markdown if it does not indicate formating.

So if you write

---
title: "test"
output: md_document
---

This will include the hash as is #tags

\#tag as first

it will be rendered as this with # escaped are none of them indicated formatting.

This will include the hash as is \#tags

\#tag as first

This is how Pandoc is working.

$ pandoc -t markdown_strict <<< "this is a #tag"
this is a \#tag

$ pandoc -t commonmark <<< "this is a #tag"
this is a \#tag

For the first # the backslash is not necessary but unharmful as \# means a literal # but still added by Pandoc. See

Thanks for the reply.

I'm rendering to md_document.

Looking at the console, this is what is running: pandoc +RTS -K512m -RTS test.utf8.md --to markdown_strict --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.md --standalone

Is it somehow possible to render tag without an escape backslash?

I am loading the .md files into another piece of software. This software processes #tag and \#tag differently.

Is it possible to add some kind of post processing to pandoc, so I could correct the output?

Thanks
-Andrew

I read the link you highlighted, and this seems to work:

---
title: "Basic Stats"
output: md_document
---

this is a `#tag`{=html}.

Thanks for your help.
-Andrew

This part with raw html is a hack that is working for your purpose. You could also raw markdown I think.

this is a `#tag`{=markdown}.`

Which software it is ? I was under the impression in markdown processor would understand the backslash escape.

Yes - thats works. Thank you.
Can I ask what the `` {} is called in rmarkdown (so I can read more about it)?

Which software it is ? I was under the impression in markdown processor would understand the backslash escape.

I'm using https://obsidian.md/
I'm writing up notes, and want to integrate code examples into my note database.

Obsidian doesn't render the \, it shows just #tag - but it doesn't create a hyperlinked tag (which it should do). The hack means that it is working as expected now.

Best
-Andrew

It is a Pandoc feature called raw attributes. Documented for Rmarkdown in

and here is the Pandoc documentation
https://pandoc.org/MANUAL.html#extension-raw_attribute

Thanks for sharing ! This is a really interesting software !
I am using Joplin which is open source for taking notes in markdown but this Obsidian looks great ! I need to have a closer look.

1 Like

Many thanks Christophe.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.