Skip to main content

Text

Standalone text is Markdownโ€‹

I can do headers

  • lists
  • lists

And other normal markdown stuff

Markdown labelโ€‹

If you want to set a Markdown label on a shape, you must explicitly declare the shape.

I can do headers

  • lists
  • lists

And other normal markdown stuff

Most languages are supportedโ€‹

D2 most likely supports any language you want to use, including non-Latin ones like Chinese, Japanese, Korean, even emojis!

ๅบŠๅ‰ๆ˜Žๆœˆๅ…‰๏ผŒ

็–‘ๆ˜ฏๅœฐไธŠ้œœใ€‚

ไธพๅคดๆœ›ๆ˜Žๆœˆ๏ผŒ

ไฝŽๅคดๆ€ๆ•…ไนกใ€‚

ใƒˆใƒžใƒˆใŒ่ตคใใชใฃใŸใฎใฏใชใœใงใ™ใ‹๏ผŸBecause it saw the salad dressing!๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ถ๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ถเบชเบฐเบšเบฒเบเบ”เบต (sabaai dii) - Laoแž‡แŸ†แžšแžถแž”แžŸแžฝแžš (jomreab suor) - Khmer

LaTeXโ€‹

You can use latex or tex to specify a LaTeX language block.

plankton will steal

A few things to note about LaTeX blocks:

  • LaTeX blocks do not respect font-size styling. Instead, you must style these inside the Latex script itself with commands:
    • \tiny{ }
    • \small{ }
    • \normal{ }
    • \large{ }
    • \huge{ }
  • Under the hood, this is using MathJax. It is not full LaTeX (full LaTeX includes a document layout engine). D2's LaTeX blocks are meant to display mathematical notation, but not support the format of existing LaTeX documents. See here for a list of all supported commands.
caution

D2 runs on the latest version of MathJax, which has a lot of nice things but unfortunately does not have linebreaks. You can kind of get around this with the displaylines command. See below.

Codeโ€‹

Change md to a programming language for code blocks

awsSessionย :=ย From(c.Request.Context()) clientย :=ย s3.New(awsSession) ctx,ย cancelFnย :=ย context.WithTimeout(c.Request.Context(),ย AWS_TIMEOUT) deferย cancelFn()awsSessionย :=ย From(c.Request.Context()) clientย :=ย s3.New(awsSession) ctx,ย cancelFnย :=ย context.WithTimeout(c.Request.Context(),ย AWS_TIMEOUT) deferย cancelFn()
Supported syntax highlighting languages

See the Chroma library for a full list of supported languages.

D2 also provides convenient short aliases:

  • md โ†’ markdown
  • tex โ†’ latex
  • js โ†’ javascript
  • go โ†’ golang
  • py โ†’ python
  • rb โ†’ ruby
  • ts โ†’ typescript

If a language isn't recognized, D2 will fall back to plain text rendering without syntax highlighting.

Advanced: Non-Markdown textโ€‹

In some cases, you may want non-Markdown text. Maybe you just don't like Markdown, or the GitHub-styling of Markdown that D2 uses, or you want to quickly change a shape to text. Just set shape: text.

A winning strategypoll the peopleresultsunfavorablefavorablewill of the people

Advanced: Block stringsโ€‹

What if you're writing Typescript where the pipe symbol | is commonly used? Just add another pipe, ||.

Actually, Typescript uses || too, so that won't work. Let's keep going.

There's probably some language or scenario where the triple pipe is used too. D2 actually allows you to use any special symbols (not alphanumeric, space, or _) after the first pipe:

Advanced: LaTeX pluginsโ€‹

D2 includes the following LaTeX plugins:

amscd pluginbraket plugincancel plugincolor plugingensymb pluginmhchem pluginphysics pluginmultilinesasmยต