How to use the command 'typst' (with examples)

How to use the command 'typst' (with examples)

The ’typst’ command is a tool that allows users to compile Typst files into PDF documents. It provides additional functionality such as listing fonts and watching for file changes during compilation. With ’typst’, users can easily create professional-looking documents from Typst source files.

Use case 1: List all discoverable fonts in the system and the given directory

Code:

typst --font-path path/to/fonts_directory fonts

Motivation: Listing all available fonts is useful when users want to see which fonts are installed on their system or check if a specific font is available in a given directory. This information can help users make informed decisions when choosing fonts to use in their Typst files.

Explanation:

  • typst: The command itself.
  • --font-path path/to/fonts_directory: This argument specifies the path to the directory where additional fonts are stored. If not provided, the command will list system fonts only.
  • fonts: This command is used to list all available fonts in the system and the given font directory.

Example output:

System Fonts:
- Arial
- Times New Roman

Font Directory Fonts:
- Open Sans
- Roboto

Use case 2: Compile a Typst file

Code:

typst compile path/to/source.typ path/to/output.pdf

Motivation: When users have a Typst file that needs to be converted into a PDF document, they can use the ’typst compile’ command. This allows users to easily generate PDF files from their source files without having to manually convert them.

Explanation:

  • typst: The command itself.
  • compile: This command is used to compile a Typst file into a PDF.
  • path/to/source.typ: This argument specifies the path to the source Typst file that needs to be compiled.
  • path/to/output.pdf: This argument specifies the path where the compiled PDF file will be saved. If not provided, the output will be saved in the same directory as the source file with the same name.

Example output:

Compilation successful. Output file: path/to/output.pdf

Use case 3: Watch a Typst file and recompile on changes

Code:

typst watch path/to/source.typ path/to/output.pdf

Motivation: The ’typst watch’ command is useful when users want to have their Typst files automatically recompiled whenever changes are made to the source file. This eliminates the need for manually running the ’typst compile’ command each time a modification is made, saving time and hassle.

Explanation:

  • typst: The command itself.
  • watch: This command sets the ’typst’ command to watch for changes in the source file.
  • path/to/source.typ: This argument specifies the path to the source Typst file that needs to be watched.
  • path/to/output.pdf: This argument specifies the path where the compiled PDF file will be saved. If not provided, the output will be saved in the same directory as the source file with the same name.

Example output:

Watching for changes in path/to/source.typ...
Recompiling...
Compilation successful. Output file: path/to/output.pdf

Conclusion:

The ’typst’ command provides a convenient and powerful way to compile Typst files into PDF documents. It offers additional functionality such as listing fonts and watching for file changes during compilation. By leveraging these features, users can easily create professional-looking documents from their Typst source files.

Related Posts

Using the airmon-ng Command to Enable Monitor Mode on Wireless Devices (with examples)

Using the airmon-ng Command to Enable Monitor Mode on Wireless Devices (with examples)

Introduction The airmon-ng command is a powerful tool included in the aircrack-ng suite that allows users to activate monitor mode on wireless network devices.

Read More
How to use the command 'find' (with examples)

How to use the command 'find' (with examples)

The ‘find’ command is a powerful tool in the Windows command prompt that allows users to search for specific text within one or more files.

Read More
How to use the command 'fold' (with examples)

How to use the command 'fold' (with examples)

The ‘fold’ command is used to wrap each line in a file to fit a specified width.

Read More