This article will demonstrate the two modes for rendering math with some of the commands provided in the markdown.
Example 1: Creating Inline Math Expression
Creating mathematical expressions in markdown is a useful technique. In this illustration, we will explore the creation of the inline math expressions in markdown.
To practically implement and compile the markdown script, we pick the Visual Studio Code tool. After launching the tool, click the new file option to create a new project file and set the file type as “Markdown” or you can use the extension “.md” to save the file as a markdown file. Open the preview window by clicking the symbol with a key on the upper right corner of the interface. Now, the output can be previewed here corresponding to the input that we enter.
We now learn how to make the inline math expressions in markdown. The inline mode math refers to the mathematical expressions that are a part of a text line or paragraph. This means that the text and the math expression are both in the same line. In this instance, we will see how we write it in the markdown.
We start with the basic and easy expression to make the inline math mode. First, we write the paragraph or a single-line text string and then the math expression is defined. We write the string as “This is the basic math expression”. Then, to write the inline math, we use the single dollar symbol ($). The “$” symbol is used before and after the math expression. Make sure that you won’t add any extra space between the dollar symbol and the expression. Markdown detects whatever expression that you add between the “$” as math code and the rest as regular text. Currently, we start with a simple math expression which is “a+b = c”. We add the dollar symbol ($). Then, without any space, we write the expression “a+b = c” and add a closing “$” sign.
The preview screen exhibits a text line and a math expression. You might have noticed that the math expression is written in a different font style which depicts that it is not a regular text but is rather a mathematical term in the LaTeX syntax.
To make the difference clear, we write the same statement without the “$” symbols to see what it yields to us.
Here, in the following snapshot of the preview window, you can see that the math expression is considered a regular text because we didn’t add the dollar signs.
You can add the math expressions anywhere in the text.
We add two mathematical formulas between the text lines to show the inline math creation in the markdown.
Now, we see how to make some complex math expressions in the markdown.
Let’s now try to make some mathematical expressions in the markdown. We create a function (f) of “y” which is having “y with power 6” and minus (-) “3” if the value of “y” is specified as “4”. The function looks as “(f(y) = y^6 -3) if (y=4)”. To write this function as inline math with some text, the text statement is “Calculate the expression:”. Then, we start the math expression by adding the “$” delimiters. Without any space, we start the round brackets. We write the function within the brackets. To add the power, use the caret (^)as the exponential operator y^6. Write the rest of the expression and then close it by the delimiter “$”.
This gives us the inline mathematical function of “y” as shown in the following image:
We now create a square root function which is provided in the following:
To make this expression, we first write the text as “This is the square root function”. Then, use the “$” delimiters to identify the math function. We add a backslash (\) after the “$” symbol. To create the square root write the “sqrt”. Next to it, the curly braces holds the expression that we want to write in square roots. The rest of the function is written in the same way that we elaborated previously.
The preview window gets us the generated function as presented in the following snapshot:
Example 2: Creating Block Mode Expression in Math
We can also create the mathematical expressions in block mode by writing them separately from the text/paragraph.
To make the mathematical expression in block mode, we use the delimiters which are two dollar signs “$$” before and after the expression. This demonstration provides you with some examples to create the block-mode math expressions.
To create a block mode math expression, separate it from the text line. Move to the new script line after adding the text and start the expression delimiters ($$). We make a sum function here. First, we add the text which is “This is block mode mathematical expression:” and then press the “Enter” key to jump to a new line. On this new line, add the double dollar symbols ($$) which depicts the start of a mathematical block expression. The expression starts with a backslash. Then, we write the “sum” command to add the summation. The underscore (_) sign is used for subscript; the curly brackets defines the values that need to be appended as a subscript expression on summation. The caret (^) symbol is used for the superscript.
The following image displays a text string. A summation function is created on the next line.
Now, let’s explore on how to create a matrix in math block mode in the markdown.
We add the delimiters to begin the expression. In the next line, we first add a backslash. Then, the “begin{bmatrix}” command is written. This is a command by markdown to generate a matrix with square brackets. Jumping to the next line, we enter the values for the matrix. We create a matrix of 3×3. The values are defined for the rows and columns. We add the double slashes (\\) at the end of each row so that the new row begins from there. Then, to close the matrix, we insert the “/end{bmatrix}” command which adds the ending square bracket.
This is our generated output matrix in the markdown.
You can also create an expression with more matrices and specified values. This way, any mathematical expression can be created in the markdown using the inline mode or block mode.
Conclusion
We often need to create mathematical expressions in the markdown for our projects or tasks. These expressions can be made in two ways: either inline math expression or block mode expression. This tutorial provided a simple and understandable guide to making mathematical expressions in the markdown. We generated some example scripts for each technique using the Visual Studio Code Software. By following these basic examples, you will be able to create simple to complex mathematical expressions easily.