Appearance
Code Block Insertion
Liii STEM provides the function of using code blocks to typeset computer program source code. This guide will help you achieve the program code standard typesetting shown in the figure below.

As shown, this is a Python code in Python code environment. Liii STEM will automatically handle font, color, and indentation in code typesetting.
Static Code Blocks
Entering Static Code Block Environment
You can enter the static code block environment in the following ways:
- In the Mode Toolbar, click
</> (Insert Computer Program)->Code Block, you can selectPlain Textto enter the environment named verbatim code. If you need to typeset C++, Scheme, or Shell code, you can also directly select the corresponding options to enter cpp code, scm code, and shell code environments.

The environment toolbar and cursor in the figure below indicate that we are in the verbatim code environment.

- After adding Python, Scala, or Goldfish macro packages, you can also click the
Code Blockoption as shown below to directly enter the corresponding python code, scala code, and goldfish code environments.

If the corresponding macro package is not added, the situation shown in the figure below will appear. At this time, you can also click
Activateto directly add the corresponding macro package.
Adjusting Code Block Environment
After entering the code block environment, you can click the Structure Variant option in the environment toolbar to switch between different language corresponding code block environments. If content has already been entered in the code block, the typesetting will change.


Typesetting Code
After setting up the code block environment, you can typeset the code content in the code block. Liii STEM will automatically handle font, color, and indentation in code typesetting.
Executable Code Blocks (Python)
In Liii STEM, you can also run desired code by inserting executable code blocks. Below we introduce this function using Python as an example.
Entering Executable Code Block Environment
To use this function, you first need to install Python on your computer. Then click Insert Session -> Python on the Mode Toolbar to enter the executable code block environment.

After entering for the first time, the page will change as shown below.

Running Code
Enter the code into the code block to run it.

Liii STEM supports importing all conda code environments.
Python Plugin Usage Instructions
You can view the detailed usage guide for the Python plugin in Help -> Plugins -> Python.

Below is a brief introduction to plugin usage.
Statement Input
Use Shift + Return/Enter keys to separate statements.

When you are ready for Python to evaluate the program you entered, click the Enter key or Return key.

If you want to input multiple lines of content at once, select Focus -> Input Options -> Multi-line Input, then you can directly click the Enter key or Return key for line breaks. When you need to run, click Multi-line Input again to close this option, then click the Enter key or Return key.


The situation shown above indicates that
Multi-line Inputis enabled.
Command Auto-completion
You can type the first letter of a built-in command or previously defined command, then press the Tab key until you find the completion option you want.

Numbering Code Lines
To number code lines, first use the command \numbered to enter the numbering environment.

Then you can insert static code blocks in the numbering environment to achieve automatic numbering of code lines

PostScript Output and matplotlib Support
Use the function ps_out(data) to output PostScript data directly to TeXmacs:
- If data is a string and has multiple lines, it will be processed as raw PostScript data.
- If data is a simple string, it is assumed to contain the filename of the PostScript file to be read (if the file has no extension, defaults will try .eps and .ps in that order).
- If data is an instance of
matplotlib.pyplot.Figure, and only when additionally using a backend that supports output to (encapsulated) PostScript, the plugin will calldata.savefig()to save the plot as a string and copy it to the TeXmacs document. - If data is a file or other object that provides a "read" method, PostScript data will be obtained by calling that method.
Help Window
If an object's source code is available through inspect.getsource(), then you can type that object followed by a question mark ? to get a popup window containing the relevant help() and code.
Used as Scripting Language
In the Menu Bar, click Insert -> Fold -> Runnable -> Python, which will generate the following output:

You can enter any Python expression or statement in the yellow box, for example:
Pressing the Return key or Enter key inside the box will switch between unevaluated input and evaluated output.

Similarly, for more complex code, you can use Shift+Return\Enter to enable multi-line input.
But note that expressions (such as 1+2) are computed using eval() and the resulting value is sent to TeXmacs, while statements (such as print "hi there", or a=1;a=a+2) are sent to compile(), during which the return value of the last statement is lost. Therefore, if you have multiple expressions, you need to write to os.sys.stdout to see inline output.
This limitation may be fixed in the future
Additionally, after selecting Document -> Script -> Python, you can also use \ + ! or Insert -> Link -> Evaluable field.


Similarly, pressing the Return/Enter key will switch between computed and uncomputed input. As shown below, notice that the environment switches between calc input and calc output.

For identifiers with associated values, you can reference these identifiers in other fields by using \ + ? or Insert -> Link -> Field reference to insert field references. You can also use pure input fields via \ + \ or Insert -> Link -> Input field. This allows dynamic documents to automatically run scripts after changing reference fields. For more information on this topic, please refer to "Plugins as Scripting Languages" in the TeXmacs documentation.
