Is there a command for generating an empty symbol with an output size of 0?

Hi there,

I use Typst to create texts, some of which are also provided by other tools.

An input data can be any ASCII text that also contains Typst commands.

My first idea was to use the raw function. Unfortunately, this does not wrap longer lines correctly and writes out of the page.

So I used “Courier New” as the font, which is generally ok. However, strings that could be a Typst command are then output as a Typst command.

Accordingly, I have written an input filter that easily converts the input characters: & becomes \&, # becomes \# and so on.

This works quite well, but input lines like

'\$recyle.bin\user123\myfile'

are a bit difficult, they become \\$ if I only replace $ and \\\\$ if I replace \ and $. Since I can only control the input character stream to a limited extent, I have switched to turning a $ into a ~\& rather than a \$. This ensures that the characters stand individually, and that input characters do not inadvertently create a command that flies around my ears.

This works reliably. Unfortunately, I have a space between the expressions due to the ~.

This doesn’t look really great in the output.

'\$recyle.bin\user123\myfile' then becomes '~\\~\$recyle.bin~\\user123~\\myfile'

Now my question: is there a character in Typst that can be used as a separator and that is not a space, but a character of length 0?

Many thanks

a#(sym.zws)b

image

There are a few built-in characters:

image

They are all part of a Unicode character set (not included in ASCII character set), there might be some other similar characters that are not a part of sym module (but still can be inserted and typeset by Typst).

1 Like

Hi, welcome and thank you for your question! I have changed your post’s title slightly to better fit the question guidelines. I also added tags, as it makes your question easier to find.

Your post was also affected by your problem because Discourse, like Typst, treats backslashes (\) specially. I put your examples in backticks (`); could you check the edit history to make sure that I did not accidentally destroy any of your examples?

I think there could be a better solution to your problem; may I ask a bit more about your situation?

Where does the text come from? Is it in a text file, or directly in Typst source code? If it’s in a text file and you read() it, there should actually be no problem at all. You get a string with the correct content, and you can insert that into your document:

#read("file.txt")

from file

Since you face this problem, I assume that you have this text directly in your Typst code, and this is not satisfactory:

'\$recyle.bin\user123\myfile'

plain text

Neither is this due to the lack of line breaks:

```
'\$recyle.bin\user123\myfile'
```

However, you can get the content from a raw block (```...```) as a string, exactly as if you had read it out of a file:

#```
'\$recyle.bin\user123\myfile'
```.text

text from raw block

This can be written as a one-liner like so:

#`'\$recyle.bin\user123\myfile'`.text

In fact, my prozess is a little more complex:

We use a tool for our reports that creates outputs in XML. A converter script runs over the output, which parses individual XML entries and generates typst code for a complex table. I can control some parts of the output well because these data is hard-coded into typst entries.

However, some parts of the XML file contains output that is completely variable. These can be long texts, lists, file paths or even Windows registry keys. In general, it can also contain excerpts from memory dumps.

I currently use the following macro:

#let textoutput(body) = {
set par(justify: false)
align(left)[#text(size: 10pt, hyphenate: true, font: “Courier New”)[#body]]
}

Additionally I change the input manually so that typst control commands are escaped by a backslash. In addition, a #(sym.zws) is entered after some characters so that long lines consisting of blocks of digits are better separated.

This works quite well for me.

In case you didn’t know (and for future visitors to this post) Typst GmbH
(the company) also provides commercial support contracts in addition to a free web app.

See at Pricing

Are you using the open-source Typst compiler in your company? We offer commercial support contracts and can help with deployment, patches, and usage. Contact us to learn more!

Just so you know, Typst supports reading xml directly: XML Function – Typst Documentation

You may be interested in these other threads:

Also to reiterate: if you use raw blocks (```...```), you don’t need to escape Typst control commands. Raw blocks can also use more that three backticks (e.g. (``````...``````) if you can’t guarantee that your inputs won’t contain ```. But you get around all needs for escaping by loading the data from file instead of putting it in your Typst source code.