Go to navigation

AsciiDoc

AsciiDoc is currently the most supported formatting language within Courses. In addition to extensive formatting options, it allows for the use of variables, conditional rendering blocks, and more. This page lists the basic and most commonly used elements. The complete syntax can be found in the official documentation.

AsciiDoc files are saved with the .adoc extension. The page title in the navigation bar is specified using the title element (see point 1 of the Metadata and attributes section).

Metadata and attributes

Each page can define various variables (attributes) that you can use to affect, for example, the page title, appearance, and so on.

A sample page may look as follows:

= Annotation 1
:toc: 2
:imagesdir: ./media/ 3
:course-guarantor: doc. Kevin Flynn 4

The course covers the fundamental principles of life.
The course guarantor is link:{course-guarantor}[]. 5
  1. Page title. Each page must have exactly one title. This title is also displayed in the navigation bar.
  2. Enable Table of Contents (can be disabled by omitting this line).
  3. Path to the image directory (optional). For more information, see Images.
  4. Definition of a custom variable.
  5. Use of the variable in the text.

For more information, see the official documentation.

Headings

Headings are an integral part of the page. Among other things, they are used to automatically generate content. More on this is shown in Metadata and attributes.

Formatting nameInput textResulting text
Heading level 1== Heading level 1

Heading level 1

Heading level 2=== Heading level 2

Heading level 2

Heading level 3==== Heading level 3

Heading level 3

Heading level 4===== Heading level 4
Heading level 4

You can assign any ID to headings. This will then appear in the URL when you click on the heading. It also makes it easy to link to it; see the example.

Example of using a heading ID

I will create a heading with the custom ID video.

[#video]
== Lecture recordings

On this page you will find a list of lecture recordings.

Later on the page I can conveniently reference the section marked this way. See Links for more.

All lectures within this course are <<+++video+++, recorded>>.

For more information, see the official documentation.

Text formatting

Formatting nameInput textResulting text
Bold*text*text
Italic_text_text
Monospaced`text`text
Quotes"`this way`"“this way”
Dash-- – 

A part of a word, not the whole word (see the following example), can be formatted using the so-called unconstrained formatting pair.

To highlight only part of a word, you need to use two asterisks instead of one.

See the official documentation for more.

Formatting nameInput textResulting text
Linkhttps://www.cvut.cz/https://www.cvut.cz
Link with custom texthttps://www.cvut.cz/[This Link points to CVUT]This Link points to CVUT
Internal linkxref:pagename.adoc#[]Note: The displayed text will be the page title.
Internal link to a headingxref:asciidoc.adoc#links[]Links
E-mailmailto:helpdesk@fit.cvut.cz[]helpdesk@fit.cvut.cz
Link within the documentxref:links[Links section]Links section

Inside the square brackets at the end of a link, you can specify custom text under which the link will be displayed.

For more information, see the official documentation.

Images

Store images in the designated folder[1]. Otherwise, the image would be automatically added as a separate page in the side navigation.

Optional[2] – In the page header, specify the folder in which AsciiDoc should look for images. Do this using :imagesdir: <relative path to the folder>. See point 3 of the Metadata and attributes section.

Examples of inserting images:

Example nameInput text
Regular image

image::image.jpg[Alternative text]

Image with caption
.This is a caption that will be displayed together with the image
image::image.jpg[Alternative text]
Image with alignment

image::image.jpg[Alternative text, align=left]

Other attributes that can be used to modify image rendering include:

  • Width width=<size>
  • Link link=<link>
  • and others

For more information, see the official documentation.

Files

  1. Add the file to the designated folder[1].
  2. On the required page, provide a link to the file in the form link:<relative path to the file>[].

Display in navigation

Files can be displayed directly in the navigation. Just place it in any folder[4] and the Course Pages Generator will include it in the navigation.

Lists

To force separation of adjacent lists, use //-.

List nameInput textResulting text
Unordered
* This is an unordered list
* This is its second item
** Another list level
* Another item
  • This is an unordered list
  • This is its second item
    • Another list level
  • Another item
Ordered
. This is an ordered list
. This is its second item
.. Another list level
. Another item
  1. This is an ordered list
  2. This is its second item
    1. Another list level
  3. Another item
Custom numbering and order change[5]
[loweralpha, start=5]
. This is an ordered list
. It is numbered with lowercase letters
** Second list level
** It is unordered
. Another item
  1. This is an ordered list
  2. It is numbered with lowercase letters
    • Second list level
    • It is unordered
  3. Another item
Multi-line items
* This is an item.
+
With multiple lines.

* This is its second item
  • This is an item.

    With multiple lines.

  • This is its second item

For more information, see the official documentation.

Code

Code can be written on a single line – for example, `text` will be rendered as text.

For multi-line code, see the following example:

[source, c]
----
airplane_t *strip = NULL;
strip = (airplane_t *) malloc(n * sizeof(*strip));

long int j = 0;
for (long int i = 0; i < n; i++)
    if (abs(P[i].x - midPoint.x) < d)
        strip[j] = P[i], j++;
----

It will be rendered as:

airplane_t *strip = NULL;
strip = (airplane_t *) malloc(n * sizeof(*strip));

long int j = 0;
for (long int i = 0; i < n; i++)
    if (abs(P[i].x - midPoint.x) < d)
        strip[j] = P[i], j++;

The [source, <language>] line handles syntax highlighting. Any language can be substituted for <language>. Omitting this line will disable syntax highlighting for the code.

For more information, see the official documentation.

Code with callouts

Callouts can be inserted into code. This lets you comment on work clearly without needing comments.

Individual callouts are a combination of two elements:

  • marker – // <1>, the type of marker can be chosen depending on the language of the example.[6]
  • comment – <1> Declaration of variables
[source, c]
-----
airplane_t *strip = NULL; // <1>
strip = (airplane_t *) malloc(n * sizeof(*strip)); // <1>

long int j = 0;
for (long int i = 0; i < n; i) // <2>
    if (abs(P[i].x - midPoint.x) < d)
        strip[j] = P[i], j;
-----

<1> Declaration of variables.
<2> Loop that runs exactly n times.

It will be rendered as:

airplane_t *strip = NULL; 1
strip = (airplane_t *) malloc(n * sizeof(*strip)); 1

long int j = 0;
for (long int i = 0; i < n; i++) 2
    if (abs(P[i].x - midPoint.x) < d)
        strip[j] = P[i], j++;
  1. Declaration of variables.
  2. Loop that runs exactly n times.

For more information, see the official documentation.

Collapsible blocks

The following code can be used to create collapsible blocks.

[%collapsible]
.Solution to homework 1
====
Here is the solution to the homework.
====

It will be rendered as:

Solution to homework 1

Here is the solution to the homework.

Comments

Comments are not part of the final page.

// Single-line comment

You can also write multi-line comments.

////
Comment that has

multiple lines.
////

For more information, see the official documentation.

Tabbed navigation

The following code can be used to create a tabbed navigation bar.

[tabbed] 1
Arch Linux:: 2
+
The first line of the Arch Linux tab.
+
The second line.
3
Debian / Ubuntu::
+
The first line of the Debian / Ubuntu tab.
+
The second line.

Fedora::
+
The first line of the Fedora tab, which also contains source code:
+
[source, c]
----
airplane_t *strip = NULL;
strip = (airplane_t *) malloc(n * sizeof(*strip));
----

openSUSE::
+
The first line of the openSUSE tab.
+
The second line.
  1. The block with tabbed navigation must be marked [tabbed].
  2. The tab name can be anything, but it must end with ::, e.g. Arch Linux::.
  3. Individual tabs are separated by a blank line.

It will be rendered as:

Arch Linux

The first line of the Arch Linux tab.

The second line.

Debian / Ubuntu

The first line of the Debian / Ubuntu tab.

The second line.

Fedora

The first line of the Fedora tab, which also contains source code:

airplane_t *strip = NULL;
strip = (airplane_t *) malloc(n * sizeof(*strip));
openSUSE

The first line of the openSUSE tab.

The second line.

Tabbed navigation inside a list

A special use case for tabbed navigation is inside a list, see the following example.

. Fill in the following fields:
+
[tabbed]
Incoming mail server::
* Protocol: `IMAP`
* Server: `{mail-imap}`
* Port: `{mail-port-imap}`
* Connection security: `SSL/TLS`
* Authentication method: `OAuth2`

Outgoing mail server::
* Protocol: `SMTP`
* Server: `{mail-smtp}`
* Port: `{mail-port-smtp}`
* Connection security: `STARTTLS`
* Authentication method: `OAuth2`

+
If the authentication method menu does not include `OAuth2`, first click btn:[Retest].
Then continue with btn:[Done].

. In the pop-up window, log in with `<username>@**cvut.cz**` and xref:../../accounts/index.adoc[the CTU password].

Blocks (admonitions)

Important:

This is a block containing important information. The block name is IMPORTANT.

Caution:

This is a block containing information that should be read carefully. The block name is CAUTION.

Warning:

This is a block containing a strong warning about imminent danger. The block name is WARNING.

Below is an example of a single-line block. Instead of NOTE, you can substitute any block type, see the names above.

Source code
NOTE: This is a block containing a note. The block name is `NOTE`.
Result

Blocks can also be multi-line; instead of IMPORTANT, you can substitute any block type, see the names above.

Source code
[IMPORTANT]
====
This is a block containing important information.

- the block name is `IMPORTANT`
- it is multi-line
- and it can also contain more complex structures (such as this list)
====
Result
Important:

This is a block containing important information.

  • the block name is IMPORTANT
  • it is multi-line
  • and it can also contain more complex structures (such as this list)

Likewise, a block can have its own title.

Source code
[TIP]
.This is a block with a title
====
Additional block text.
====
Result

For more information, see the official documentation.

Collision with page contents

If an admonition block is used at the top of the page together with the page contents (ToC), a collision may occur (see the following image).

admonition toc collision before cs
Figure 1. Admonition block colliding with page contents (ToC).

In such a case, the collision can be disabled using the noclear class.

[.noclear]
TIP: Enter which grading system you use (for example, https://grades.fit.cvut.cz[Grades/Classification]).
admonition toc collision after cs
Figure 2. Admonition block after collision has been disabled.

Footnotes

A footnote can be written using footnote:[Footnote text.] at the desired place in the text. AsciiDoc handles the numbering automatically.

The result will look as follows.[7]

Reusing a footnote

A specific footnote can be referenced multiple times. Create a footnote using footnote:<footnote-id>[<footnote-text>]. You can reference an existing footnote using footnote:<footnote-id>[]. Replace <footnote-id> with any footnote identifier.

For more information, see the official documentation.

Tables

AsciiDoc provides comprehensive support for creating tables, including cell merging, different alignment options, or loading data from a CSV file.[8]

Example of a simple table without formatting:

Source code
[%header, cols="1,1,2"] 1
|=== 2
|Name
|Password
|Description

|user 3
|1234
|Regular user

|root
|root
|Superuser
|=== 2
  1. Optional: List of attributes. The %header" attribute marks the first row as the table header. cols="1,1,2" specifies three columns, where the third is twice as wide.
  2. Required: The table must be enclosed by the string |===.
  3. Individual table rows in the source code are separated by a blank line.
Result
NamePasswordDescription
user1234Regular user
rootrootSuperuser

The following can be modified in tables:

  • Formatting and alignment of columns[9]
  • Merging, formatting, or alignment of cells[10]
  • Width and alignment of the entire table[11]
  • etc.

For more information, see the official documentation.

Advanced formatting

Source code
.Course grading 1
[%header] 2
[cols="^1s, 2, 2"] 3
[width=50%] 4
[align=left] 5
|====
|Grade
|Point range
|Verbal assessment

|A
|90 and above
|excellent

|B
|80-89
|very good

|C
|70-79
|good

|D
|60-69
|satisfactory

|E
|50-59
|sufficient

|F
|less than 50
|insufficient
|====
  1. Optional: Table title.
  2. %header marks the first row of the table as the header.
  3. cols="^1s, 2, 2" the first column of the table will be centered (^) and highlighted in bold (s), the remaining columns will be twice as wide.
  4. width=50% the table width will be 50% of the page width.
  5. align=left the table will be aligned to the left as a whole.
Result
Table 1. Course grading
GradePoint rangeVerbal assessment
A90 and aboveexcellent
B80-89very good
C70-79good
D60-69satisfactory
E50-59sufficient
Fless than 50insufficient

Data from a file

Example of an alternative data source:

Source code
[%header, format=csv, separator=;, cols="1,1,2"]
|===
include::tracks.csv[]
|===
tracks.csv
Exercise;Date;Exercise content
1;23. 9. 2020;Basic concepts
2;30. 9. 2020;Chomsky hierarchy
Result
ExerciseDateExercise content
123. 9. 2020Basic concepts
230. 9. 2020Chomsky hierarchy

Mathematical expressions

To use mathematical expressions and formulas entered using La/TeX syntax on the page, we must correctly set the document’s stem attribute to latexmath. This can be easily done as follows:

= Page with mathematical expressions 1
:stem: latexmath 2
  1. Document/page title.
  2. Set the stem attribute to latexmath.

Courses use KaTeX to render mathematical expressions in the final output. This is a tool that allows mathematical expressions written in La/TeX syntax to be displayed on the web. It was originally created for Khan Academy. KaTeX does not support absolutely all mathematical features and packages known from La/TeX or AMSTeX, but its capabilities are fully sufficient for most users and problems. The exact list of supported macros and environments is given in the KaTeX documentation.

Equations in text

To create mathematical expressions appearing directly in the text (inline math), you can use the stem macro. For example, we might want to discuss the properties of the function f(x)=sin(x)f(x) = \sin(x) or talk about the sequence (n+1)n=1(n+1)_{n=1}^\infty. The source code of such a sentence with mathematical expressions looks like this:

For example, we might want to discuss the properties of the function stem:[f(x) = \sin(x)]
or talk about the sequence stem:[(n+1)_{n=1}^\infty].

The stem macro is therefore practically equivalent to LaTeX math mode enclosed in two $ symbols. However, we must pay attention to the closing square bracket that marks the optional parameters of some LaTeX macros; for example, the cube root of two, 23\sqrt[3]{2}, is written correctly using

stem:[\sqrt[3\]{2}] 1
  1. Notice \] instead of ].

Standalone equations

To typeset a larger equation that needs to stand on its own line, we use a block enclosed by four + symbols (the content of this block is not modified in any way and is sent directly to KaTeX; passthrough block) with the stem style. For example, the equation

k=1k=112,\sum_{k=1}^\infty k = -\frac{1}{12}\,,

was created using the code

[stem] 1
++++ 2
  \sum_{k=1}^\infty k = -\frac{1}{12}\,, 3
++++ 4
  1. stem style.
  2. Start of the block.
  3. Content of the block with mathematical LaTeX notation.
  4. End of the block.

Such a block therefore corresponds to the standard unnumbered LaTeX equation* environment, or to LaTeX math mode enclosed by \[ and \].

Often, however, we need to typeset several equations at once and want to align them nicely. For that, we can use the aligned environment. The following system of two equations in two variables

2x+3y=4,5x+6y=7.\begin{aligned} 2x + 3y &= 4, \\ 5x + 6y &= 7. \end{aligned}

was created using the code

[stem]
++++
\begin{aligned} 1
  2x + 3y &= 4, \\ 2
  5x + 6y &= 7.
\end{aligned}
++++
  1. Use of the aligned macro to align multiple equations.
  2. We use the & symbol to align equations and \\ to separate them.

In KaTeX, besides the aligned macro, there is another macro known from AMSTeX, gathered, which allows typesetting of multi-line centered equations without alignment, for example

(x+y)n=k=0n(nk)xnkyk==(n0)xn+(n1)xn1y+(n2)xn2y2++(nn1)xyn1+(nn)yn.\begin{gathered} (x + y)^n = \sum_{k=0}^n \dbinom{n}{k} x^{n-k} y^k = \\ = \dbinom{n}{0} x^n + \dbinom{n}{1} x^{n-1} y + \dbinom{n}{2} x^{n-2} y^2 + \cdots + \dbinom{n}{n-1} x y^{n-1} + \dbinom{n}{n} y^n\,. \end{gathered}

We created this equation using the following code:

[stem]
++++
\begin{gathered} 1
  (x + y)^n = \sum_{k=0}^n \dbinom{n}{k} x^{n-k} y^k = \\ 2
  = \dbinom{n}{0} x^n + \dbinom{n}{1} x^{n-1} y + \dbinom{n}{2} x^{n-2} y^2
  + \cdots + \dbinom{n}{n-1} x y^{n-1} + \dbinom{n}{n} y^n\,.
\end{gathered}
++++
  1. Use of the gathered macro to center a multi-line equation.
  2. We use \\ to break the equation.

More math tips and tricks

References to equations

In mathematical text, it is customary to refer to some (numbered) equations. However, KaTeX/AsciiDoc/Course Pages do not directly support the LaTeX macros label and eqref, respectively ref. We can, however, work around this quite easily because KaTeX supports the tag macro. We mark the relevant block containing the equation we want to reference with an ID, add a tag to the equation, and use the AsciiDoc xref macro in the reference. For example, the following equation

(1)abf(x)dx=[F(x)]ab.\tag{1} \int_{a}^{b} f(x)\,\mathrm{d}x = \big[ F(x) \big]_{a}^{b}\,.

was typeset using the code

[#eq1]
[stem]
++++
  \tag{1}
  \int_{a}^{b} f(x)\,\mathrm{d}x = \big[ F(x) \big]_{a}^{b}\,.
++++

In equation (1) (reference created using xref:eq1[(1)]), the attentive reader will surely recognize Newton’s formula.

Highlighting parts of equations

To draw attention to important parts of an equation, we can use braces (the underbrace macro) or even colors (the color macro), for example in the equation

(abcd)1=1adbc(dbca).\underbrace{ \begin{pmatrix} a & b \\ c & d \end{pmatrix}^{-1} }_{\triangle} = \frac{1}{\color{red}ad-bc} \begin{pmatrix} d & -b \\ -c & a \end{pmatrix}.

we marked the matrix on the left side with a triangle (\triangle) and the expression in the denominator on the right side in red. The code used is as follows:

[stem]
++++
  \underbrace{ 1
  \begin{pmatrix}
    a & b \\
    c & d
  \end{pmatrix}^{-1}
  }_{\triangle}
  =
  \frac{1}{\color{red}ad-bc} \begin{pmatrix} 2
    d  & -b \\
    -c & a
  \end{pmatrix}.
++++
  1. The underbrace macro.
  2. The color macro.

Definitions, theorems and proofs

In more formal mathematical texts, it is customary to typographically separate important parts such as Definitions, Theorems, and so on. In LaTeX, the well-known amsthm package exists for this purpose.

In AsciiDoc/Courses, we can use, for example, a named block intended for a quotation to create such a typographical separation. Below is one specific example of this approach.

Fundamental Theorem of Algebra

Every polynomial of degree nNn \in \mathbb{N} has at most nn complex roots.

The code used to create this highlighted section is as follows:

.Fundamental Theorem of Algebra 1
[#Veta1] 2
____ 3
Every polynomial of degree stem:[n \in \mathbb{N}] has at most stem:[n] complex roots.
____
  1. Title.
  2. id used to reference the theorem in the text.
  3. Block enclosed by four underscores.

For the ceremonial marking of the end of a proof, mathematical literature usually uses the Halmos tombstone \square, or a square. This can be created with KaTeX using the code stem:[\square]. Alternatively, of course, a plain text abbreviation Q.E.D. can be used.

Diagrams

The course-pages generator integrates the Kroki diagram generator. This allows it to render many different kinds of diagrams, such as WaveDrom, Graphviz, and many others.

Just as with source code, the diagram code must be placed in a block, and the diagram type must be placed in square brackets above the block.

Example of rendering a graph using Graphviz:

[graphviz]
....
digraph G {
    "Node 1" -> "Node 2";
    "Node 2" -> "Node 3";
}
....

Result:

graph viz example en

Example of rendering a graph using WaveDrom:

[wavedrom]
....
{
  signal: [
    { name: 'Clock', wave: 'P......' },
    { name: 'Data',  wave: 'x.345x', data: ['D0', 'D1', 'D2', 'D3'] },
    { name: 'Enable', wave: '0.1..0' }
  ]
}
....

Result:

wave drom example en

  1. By default, this is the media or files folder, but the name may vary depending on the configuration of the given project.
  2. If you do not specify the :imagesdir: attribute, you will need to provide the full path for each image.
  3. Microsoft OneDrive also provides advanced methods for access management and permission assignment.
  4. Outside paths that are hidden by settings – the hiddenFiles and excludedFiles settings in the configuration file. Typically the media or files folders.
  5. Alternatively, you can number in reverse order using the %reversed flag
  6. Instead of // <1>, you can use for example # <1>, ;; <1>, <!--1-->. The marker should be a valid comment in the given language.
  7. Footnote text.
  8. For more on the data format, see the official documentation.
  9. For more on column formatting, see the official documentation.
  10. For more on cell formatting, see the official documentation.
  11. For more on table width, see the official documentation.