LaTeX/C3/newenvironment-in-LaTeX/English
Title of script: New Environments
Author: Ambika Vanchinathan
Keywords: New environment, renewenvironment, define environments in LaTeX, \newenvironment, \renewenvironment, video tutorial
Visual Cue | Narration |
Slide | Welcome to the spoken tutorial on creating new environments in LaTeX. |
Slide:Learning Objectives | This tutorial will help the learners to
|
Slide: Pre-requisites | To follow this tutorial,
|
Slide:System Requirements | To record this tutorial, I am using
|
slide: New Environment | Just like new commands, we can define new environments.
|
slide: New Environment | New environment is a variation of executing few existing commands put together in a sequence.
|
slide: New environment | The syntax to define a new environment is
\newenvironment{environment name}{start commands}{end commands}
And end commands are performed whenever the environment ends.
|
Open the TeXWorks editor | Let us open the TeXWorks editor. |
Pause the tutorial at this point.
Download and unzip the files provided in the Code Files link below the player. | |
Switch to the code file
|
You will see some LaTeX
code given in the file newEnv.tex |
(copy/paste the following in TeXWorks)
\usepackage{color} \newenvironment{bluetext} {\begin{center}\color{blue}} {\end{center}} \begin{document} This text is outside the new environment. This text is outside the new environment. This text is outside the new environment. \begin{bluetext} Testing to see whether this text is in blue colour. \end{bluetext} some more text \end{document} |
We will copy and paste the first block of code from this file into our newly opened tex file.
|
Let’s try to understand the program. | |
Point to the exact line as per narration | Here \newenvironment{bluetext}
means that we are defining a new environment called bluetext. |
Point to the exact line as per narration | Here in the definition we center the text and colour it with blue using
{\begin{center}\color{blue}} {\end{center}}
|
Save as newEnv.tex | Save the file as newEnv.tex |
Compile >> Point to the pdf output | Let us compile and see the output.
|
<<PAUSE>> | |
We will now see how to use parameters in the environments. | |
slide: New environment with parameters | New environment with parameter is defined as
\newenvironment{environment name}[parameters]{start commands}{end commands}
|
open a new file in TeXWorks | Let’s open a new file in TeXWorks. |
Switch to the code file | Now switch to our downloaded code file. |
(copy/paste the following)
\usepackage{color} \newenvironment{bluetext}[1] {\begin{center}\color{blue} \textbf{\textit{#1}}\\[12pt] } {\end{center}} \begin{document} This text is outside the new environment. This text is outside the new environment. This text is outside the new environment. \begin{bluetext}{My text in blue} Testing to see whether this text is in blue colour. \end{bluetext} some more text \end{document} |
Now, we will copy the next block of code from our downloaded
code file and paste it into our new teX file.
|
Point to the exact line as per narration
|
Let us understand the code now.
|
Point to the exact line as per narration | We have just added
\textbf{\textit{#1}}\\[12pt] to the code given for the environment without parameter |
Point to the exact line as per narration | * We use it as “\begin{bluetext}{My text in blue}”
|
Save file as newEnvp1.tex | Save the file as newEnvp1.tex |
Compile >> point to the pdf | Now compile and see the output. |
<<PAUSE>> | |
We shall see the renewenvironment now. | |
slide: renewenvironment
|
renewenvironment is used to change or overwrite the existing environment.
\renewenvironment{env}{start commands}{end commands}
|
Open a new tex file. | Once again, we will open a new tex file. |
(copy/paste the following)
\renewenvironment{itemize}{\begin{center}\large }{\end{center}} \begin{document} This text is outside the new environment. This text is outside the new environment. This text is outside the new environment. \begin{itemize} Text inside itemize
\end{itemize} \end{document} |
We will copy and paste the last block of code from our downloaded file into our newly opened tex file.
|
Point to the exact line as per narration | Let us understand the code.
|
Recall that the itemize environment creates a list according to the original definition. | |
Point to the exact line as per narration | Let’s see the usage.
should be
|
Save code to renewEnv.tex | Let us save the file as renewEnv.tex and compile the tex file. |
Point to the PDF output | Observe the output. |
Slide: Summary | To summarise, we have learnt
|
slide: Assignment | Create an environment itemizecolor, which takes the color (red, blue, yellow, green) as input and creates a list in that color. |
Slide: Acknowledgement | The video at the following link summarises the Spoken Tutorial project.
Pls watch it. |
Slide | The Spoken Tutorial Project Team :
Conducts workshops using spoken tutorials and Gives certificates to those who pass an online test For more details, please write to us. |
Slide | Spoken Tutorial Project is funded by the NMEICT, MHRD, Government of India.
Thanks for joining. |