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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s