Skip to content

Creating Custom Macro Commands ​

Liii STEM supports custom macros and direct macro import from LaTeX\LaTeX. Macros are useful for wrapping frequently used content, formula structures, and typesetting styles.

0 Terminology ​

  • Environment: A region with a specific structure and behavior. The same content may be rendered differently in different environments.
  • Markup: The name of an environment, such as section.
  • Focus: The environment where the cursor is currently located. It is usually shown with a blue frame in the interface.
  • Typesetting primitive (Primitive): A basic built-in operation in the Liii STEM style language, such as <with|>, <if|>, and <equal|>.
  • Macro: A reusable command assembled from primitives. You can customize macros as needed.
  • Tag: A basic typesetting unit in Liii STEM used to describe structure and formatting.
  • Structure: The rendered typesetting result produced by primitives or macros.
  • Structured input / movement: Insertion, deletion, and movement performed by document logic units. For example, in a table, Alt + Left and Alt + Right insert columns, Alt + Up and Alt + Down insert rows, and Alt + Backspace and Alt + Delete perform structured deletion.

1 What Is a Macro? ​

A macro wraps repeated input into a short command. For example, you can define Southern University of Science and Technology as sustech, then type only the macro name later.

2 Basic Macro Usage ​

Create a Macro ​

In the menu bar, click Tools -> Macro commands -> New macro. Enter the macro name in enter-name, enter the macro content in enter-body, then click Use -> Confirm. After the macro is created, press \, type the macro name, and press Enter to call it.

Add Parameters ​

Open Macro editor and switch the lower-left mode to Math. Use Alt + Right to add parameter slots. After that, each macro call can fill those parameter slots with different content.

Define Existing Macros ​

Click Preference for tag -> Edit macro in the focus toolbar to open the macro editor. For complex macros, switch to Source mode or edit directly in the preamble.

3 Edit Macros in the Preamble ​

Open the Preamble ​

Click Document -> Part -> Show preamble, or use the shortcut Ctrl + Shift + P.

Edit Macros in the Preamble ​

After entering the preamble, you can directly edit existing macro names, parameters, and bodies.

Create Macros in the Preamble ​

Type \assign to generate the <assign||> structure. Enter the macro name after the first |, and enter the macro body after the second |.

Common Tips ​

  • If a macro needs parameters, type \macro first, then use Alt + Right to add parameters.
  • Complex structures can nest existing macros. When editing structures such as matrices, you can first click Activate in the mode toolbar to expand the structure, then edit it.
  • Type \math to enter Math Mode, so you can call Math Mode macros directly inside a macro body.
  • When using conditional primitives such as if, editing in the preamble is usually more convenient.

Conditional Example ​

text
<assign|test-equal|<macro|arg1|arg2|msg|<if|<equal|arg1|arg2>|Same quantity:arg1|Not equal:msg>>>

This example defines a test-equal macro that checks whether two parameters are equal.

4 Import Macros from LaTeX ​

Liii STEM supports direct macro import from LaTeX\LaTeX, which is convenient when migrating existing LaTeX\LaTeX commands into Liii STEM.

5 Quickly Get Familiar with Macro Commands ​

Use Ctrl + Shift + o to view the document source. Comparing the document output with the source structure is one of the fastest ways to become familiar with macro commands.

6 Mogan Style Language ​

If you need to write more complex macros, start with the following common structures.

Assignment ​

text
<assign|hi|<macro|Hi there!>>

assign permanently sets an environment variable.

text
<with|font-series|bold|color|red|Bold red text>

with locally changes environment variables.

text
<with|strong|<macro|body|<with|font-series|bold|color|red|body>>|<strong|strong> text>

with can also be used for local macro redefinition. The value primitive is often used to read the value of an environment variable.

Macro Expansion ​

text
<assign|my-macro|<macro|x1|...|xn|body>>
text
<my-macro|y1|...|yn>

The first snippet defines a macro, and the second snippet calls it.

text
<assign|hello|<macro|name|Hello <arg|name>, you look nice today!>>

arg reads an argument value.

text
<assign|hey|
  <macro|first|second|
    <if|
      <equal|second|?>|
      Hey <arg|first>, you look lonely today...|
      Hey <arg|first> and <arg|second>, you form a nice couple!>>>

Extra arguments are ignored when calling a macro. Missing arguments are treated as uninit.

text
<assign|my-macro-copy|my-macro>

You can also assign one macro to another environment variable.

Formatting Primitives ​

frac is a typical inline tag, and Theorem is a typical block-level tag. concat is used for inline concatenation, while document is used for paragraph-level organization. When writing a macro, if you need inline text around a block-level tag, use surround.

text
<assign|my-theorem|
  <macro|body|
    <surround|<no-indent><with|font-series|bold|Theorem. >|<right-flush>|
      body>>>

text
<assign|very-important|<macro|body|<with|font-series|bold|color|red|body>>>
text
<assign|very-important|
  <macro|body|
    <with|font-series|bold|color|red|
      <document|body>>>>

If you want a tag to always be handled as a block-level structure, use document inside it.

Basic Table Structure Tags ​

text
<assign|eqnarray*|
  <macro|body|
    <with|par-mode|center|mode|math|math-display|true|par-sep|0.45fn|
      <surround|<no-page-break*><vspace*|0.5fn>|<vspace|0.5fn><no-indent*>|
        <tformat|
          <twith|table-hyphen|y>
          <twith|table-width|1par>
          <twith|table-min-cols|3>
          <twith|table-max-cols|3>
          <cwith|1|-1|1|1|cell-hpart|1>
          <cwith|1|-1|-1|-1|cell-hpart|1>
          body>>>>>

In this example, surround wraps a block-level environment, tformat describes the table structure, and twith and cwith set table-level and cell-level properties.

text
<tabular|
  <tformat|
    <table|
      <row|<cell|A1>|<cell|B1>>
      <row|<cell|A2>|<cell|B2>>>>>

This is the most basic table structure example.

text
<tabular|
  <tformat|
    <!-- Table-level property settings -->
    <twith|property-name|property-value>
    <twith|property-name|property-value>
    ...

    <!-- Cell-level property settings -->
    <cwith|row-range|column-range|property-name|property-value>
    <cwith|row-range|column-range|property-name|property-value>
    ...

    <!-- Table content -->
    <table|
      <row|<cell||>|<cell||>>
      <row|<cell||>|<cell||>>>>>

To learn more about the underlying language, see Scheme Quick Start.