Skip to contents

The 'munch' package renders rich inline text (bold, italic, code, links, images, equations) in grid graphics and 'ggplot2', from markdown or 'flextable' chunks.

For 'ggplot2' integration, use element_md() and element_chunks() in theme elements, or geom_text_md() and geom_label_md() for annotations.

Advanced usage

Use md_grob() to convert markdown text to a grid grob, or chunks_grob() to convert 'flextable' paragraph objects (for superscripts, subscripts, and custom colors not available in markdown).

Limitations

Only graphics devices that support 'systemfonts' are compatible: 'ragg', 'svglite', or 'ggiraph'. The cairo_pdf() device is also supported when fonts are installed at the system level, except on Windows, where it does not apply the kerning of the fonts: words are drawn wider than measured. Standard R devices (pdf(), png(), jpeg()) are not compatible but can still produce correct output if fonts are made available to the device (e.g. via 'extrafont'). See vignette("font-recipes") for details.

Equations, written $...$ and $$...$$ in markdown (as in Pandoc) or created with flextable::as_equation(), are drawn with the package 'equatags' (R >= 4.3); without it, their LaTeX source is written as text. A $$...$$ equation is alone on its line, in display style. For simple scientific notation, as_sup() and as_sub() from 'flextable' are enough.

Only inline formatting is supported: bold, italic, code, strikethrough, links, images, superscripts (^2^), subscripts (~2~) and equations. Superscripts, subscripts and equations follow the markdown of Pandoc (R Markdown, Quarto). Block elements such as headings, bullet lists, and numbered lists are not available.

Text format

The format of a text (size, font family, colour, bold, italic) comes from its chunk or its markdown, then from the element or the aesthetic and the 'ggplot2' theme, then from flextable::set_flextable_defaults(). An empty font family, the default of the themes, does not set the font: the font of the flextable defaults is used. Texts drawn by 'ggplot2' itself, such as axis labels, then use the default font of the device; give a font to the theme, for example theme_minimal(base_family = "Liberation Sans"), so that all texts of the plot use the same font.

Options

munch.skip_device_check

If set to TRUE, the device compatibility warning is suppressed. Use this when you have ensured that the fonts used by 'munch' are available to the active graphics device (e.g. via 'extrafont' for pdf()). Set with options(munch.skip_device_check = TRUE).

Author

Maintainer: David Gohel david.gohel@ardata.fr

Authors:

Other contributors:

  • ArData [copyright holder]