Tag Archives: LaTex

Modifying Text and Creating Commands in LaTeX

In this post, we are going to explore to separate features available in LaTeX. These two features are modifying the text size and creating custom commands.

Modifying Text

You can change the size and shape of text using many different declarations/environments in LaTeX. Declarations and environments serve the same purpose the difference is in the readability of the code. In the example below, we use an environment to make the text bigger than normal. The code is first followed by the example

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
\begin{huge}
\blindtext
\end{huge}
\end{document}

1.png

Here is what we did.

  1. We create a document with the class of article
  2. We used the “babel” and “blindtext” packages to create some filler text.
  3. Next, we began the document
  4. We create the environment “huge” for enlarging the text.
  5. We used the declaration  “\blindtext” to create the paragraph
  6. We closed the “huge” environment with the “end” declaration
  7. We end the document

If you ran this code you will notice the size of the text is larger than normal. Of course, you can bold and do many more complex things to the text simultaneously. Below is the same example but with the text bold and in italics

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
\begin{huge}
\bfseries
\textit
\blindtext
\end{huge}
\end{document}

1.png

The code is mostly the same with the addition of “\bfseries” for bold and  “\texit” for italics.

Making Commands

It is also possible to make custom commands in LaTeX. This can save a lot of time for repetitive practices. In the example below, we create a command to automatically print the name of this blog’s web address.

\documentclass{article}
\newcommand{\ert}{\bfseries{educationalresearchtechniques}}
\begin{document}
The coolest blog on the web is \ert
\end{document}

1.png

In the code, we use the declaration “\newcommand” in the preamble. This declaration had the command “\ert” which is the shorthand for the code to the right which is “\bfseries{educationalresearchtechniques}. This code tells LaTeX to bold the contents inside the brackets.

The next step was to begin the document. Notice how we used the “\ert” declaration and the entire word educationalresearchtechniques was printed in bold in the actual pdf.

It is also possible to make commands that format text. Below is an example.

\documentclass{article}
\newcommand{\mod}[1]{\textbf{\textit{#1}}}
\begin{document}
The is an example of modified \mod{text}
\end{document}

1.png

What is new is in line 2. Here we use the “\newcommand” declaration again but this time we create a command call “\mode” and give it an argument of 1 (see [1]) this is more important when you have more than one argument. Next, we put in curly brackets what we want to be done to the text. Here we want the text to be bold “\textbf” and in italics “\textit”. Lastly, we set the definition {#1}. Definition works with arguments in that argument 1 uses definition 1, argument 2 uses definition 2, etc.  Having more than one argument and definition can be confusing for beginners so this will not be explored for now.

Conclusion

This post provided assistance in understanding LaTeX’s font size capabilities as well as ways to make new commands.

Advertisements

Basics of LateX

In this post, we will explore more concepts about Latex the typesetting language.

Optional Commands

Optional commands appear in brackets [   ]  when you are using Latex. In the example below, we will set the font size to 20pt in the preamble of the document. The code is as follows.

\documentclass[4paper,12pt]{article} \begin{document} 
     Behold the power of \LaTeX
\end{document}

Here is what it looks like

Screenshot 2018-02-05 14:01:57.png

Inside the brackets, we set the paper size to A4 and the font size to 12pt. Many if not most commands have optional commands that can be used to customize the behavior of the document.

Comments

Like most coding languages Latex allows you to make comments. To do this you need to place a % sign in front of your comment. As shown below

\documentclass[4paper,12pt]{article} \begin{document} 
   Behold the power of \LaTeX
   %This will not print
\end{document}

Screenshot 2018-02-05 14:01:57

Everything after the % did not print. To stop this action simply press enter to move to the next line and you can continue with your document.

Fun with Fonts

There are many different ways to set the fonts. Generally, you can use the \text**{  } code. Where the asterisks are is where you can specify the behavior you want of the text. Below is a simple example of the use of several different formats to the font.

\documentclass[4paper,12pt]{article} 
\begin{document} 
   You can \textit{italicized} 
   Text can be \textsl{slanted} 
   Off course, you can \textbf{bold} text 
   You can also make text in \textsc{small caps} 
   It is also possible to use several commands at the same \textit{\textbf{time}} 
   Behold the power of \LaTeX  
\end{document}

Screenshot 2018-02-05 14:01:57.png

Notice how you put the command in front of the word that you want to format. This might seem cumbersome. However, once you get comfortable with this it is much faster to format documents then the point and click style of Word.

Environments

If you want a certain effect to last for awhile you can use an environment. An environment is a space you declare in your document in which a center behavior takes place. Generally, environments are used to improve the readability of your code. Below is an example.

\documentclass[4paper,12pt]{article} 
    \begin{document} 
        \begin{bfseries} 
            Everything is bold here 
        \end{bfseries} 
        \begin{itshape} 
            Everything is bold here 
        \end{itshape} 
        Behold the power of \LaTeX  
   \end{document}

Screenshot 2018-02-05 14:01:57

An environment always begins with the \begin command and ends with the \end command. In the curly braces, you type whatever is required for your formatting goals. There are scores of commands you can place inside the curly braces.

Conclusion

There is so much more to learn but this is just a beginning. One of the main benefits of learning Latex is the fixed nature of the formatting and the speed at which you can produce content once you are familiar with how to use this language.