Demonstration 34: Advanced Macro Capabilities

MarkCharm Team

September 11, 2026

1 Simple and Positional Macros

The most basic way to use macros is with numeric positional parameters, replacing old syntax (#1) with explicit brace syntax (#{1}).

Definition Code:

\​newcommand{saudacao}{Hello, #{1}! Welcome to MarkCharm.}

Invocation Code and Result:

\​saudacao{User}

\​saudacao{Developer}

Hello, User! Welcome to MarkCharm.

Hello, Developer! Welcome to MarkCharm.

2 Named Parameters and Default Values

We can create more descriptive macros by defining named parameters. It is also possible to assign default values when parameters are omitted during invocation.

Definition Code:

\​newcommand{alerta}[tipo=info, cor=blue]{
    <div style="border-left: 4px solid #{cor}; padding: 10px; background: #f9f9f9; margin-bottom: 15px;">
        <strong>#{tipo}:</strong> #{1}
    </div>
}

When calling the macro without named parameters, it will use the defaults (info and blue):

Invocation Code and Result:

\​alerta{System initialized successfully.}
info: System initialized successfully.

We can override parameters (with or without internal quotes):

Invocation Code and Result:

\​alerta[tipo=Warning, cor=orange]{Disk space is running low.}

\​alerta[tipo="Critical Error", cor=red]{Database connection failed!}
Warning: Disk space is running low.
Critical Error: Database connection failed!

3 Strings with Quotes and Commas

When passing parameters containing commas, protect them with double quotes in the invocation; otherwise the interpreter would split arguments at the wrong location. MarkCharm automatically strips surrounding quotes during interpolation.

Definition Code:

\​newcommand{destaque}[texto="No text", destaque_bg=yellow]{
    <span style="background-color: #{destaque_bg}; padding: 2px 4px; border-radius: 4px;">#{texto}</span>
}

Invocation Code and Result:

\​destaque[texto="This text contains commas, spaces and punctuation", destaque_bg=lightgreen]

This text contains commas, spaces and punctuation

4 High Complexity: Nesting and Cross Textual Interpolation

Thanks to parser robustness (support for up to 3 levels of nesting), complex document commands can be invoked and macros passed inside other directives.

Definition Code:

\​newcommand{cartao_perfil}[nome=Anonymous, ocupacao="Unspecified role", avatar="default.png"]{
    <div class="perfil-card" style="display: flex; gap: 15px; border: 1px solid #ccc; padding: 15px;">
        <img data="#{avatar}" width="50" height="50" style="border-radius: 50%;">
        <div>
            <h3 style="margin: 0;">#{nome}</h3>
            <p style="margin: 5px 0 0 0; color: #666;">#{ocupacao}</p>
        </div>
    </div>
}

Invocation Code and Result:

\​cartao_perfil[nome="John Doe", ocupacao="Software Engineer, AI Specialist", avatar="https://via.placeholder.com/50"]

\​cartao_perfil[nome="Jane Smith, PhD", ocupacao="Scientific Researcher"]

John Doe

Software Engineer, AI Specialist

Jane Smith, PhD

Scientific Researcher


Note

Technical Caveats The new #{...} delimiter should be preferred in all constructs to avoid conflict with hexadecimal color codes (e.g. #666). Strings passed to named parameters containing commas (,) MUST use double quotes.

5 Parameter Escaping and Math Coexistence

The #{...} delimiter was engineered not to conflict with math environments. Engines like MathJax and KaTeX internally use old syntax (#1) and commands with backslashes in their names. MarkCharm safely ignores definitions whose macro syntax includes a backslash (\name), passing it intact to the math processor.

Additionally, if you need to write programming code (like Ruby or MyBatis SQL queries) inside a MarkCharm macro and literally generate #{...} syntax, simply escape it with a backslash \#{...}.

$$
\newcommand{\vetor}[1]{\mathbf{#1}}
\vetor{v} = \vetor{x} + \vetor{y}
$$
\[\newcommand{\vetor}[1]{\mathbf{#1}} \vetor{v} = \vetor{x} + \vetor{y} \]
(1)