LaTeX/C3/newenvironment-in-LaTeX/English

From Script | Spoken-Tutorial
Revision as of 13:37, 14 September 2015 by Ambika (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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
  • create or define new environments to get customized output.
  • redefine the existing environments.


Slide: Pre-requisites To follow this tutorial,
  1. You should have knowledge of commands that are necessary to create a document in LaTeX.
  2. You should also have knowledge of compiling and producing a PDF output in LaTeX.
  3. If not, please go through the relevant LaTeX spoken tutorials on this website.


Slide:System Requirements To record this tutorial, I am using
  • Ubuntu Linux 14.04 operating system
  • TeXWorks 0.5


slide: New Environment Just like new commands, we can define new environments.


As the name suggests the command newenvironment is used to create/define a new environment.


It is used to format blocks of text, generally.

slide: New Environment New environment is a variation of executing few existing commands put together in a sequence.


Ensure that the custom environment you create, is not an already existing LaTeX environment.

slide: New environment The syntax to define a new environment is

\newenvironment{environment name}{start commands}{end commands}


Here the start commands are done whenever the environment starts.

And end commands are performed whenever the environment ends.



Open the TeXWorks editor Let us open the TeXWorks editor.
(copy/paste the following in TeXWorks)


\documentclass{article}

\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}

Type the code as shown here into the tex file.
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}}


While using it, we just give \begin{bluetext} and \end{bluetext} with the intended text between the two.

Save as newEnv.tex Save the file as newEnv.tex
Compile >> Point to the pdf output Let us compile and see the output.


Observe the blue text in 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.
(copy/paste the following)


\documentclass{article}

\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 code given here into our TeX file.
Point to the exact line as per narration


Let us understand the code now.


Here in the given code, we are adding a title to the blue text by getting the title as an input parameter.

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}”
  • and the text,
  • and then “\end{bluetext}”


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.


The syntax for renewenvironment is

\renewenvironment{env}{start commands}{end commands}


It’s quite similar to newcommand.

Open a new tex file. Open a new tex file.
(copy/paste the following)


\documentclass{article}

\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


Lets check the output

\end{itemize}

\end{document}

Type the code as given here.
Point to the exact line as per narration Let us understand the code.


\renewcommand{itemize} redefines the itemize environment.


It is defined as {\begin{center}\large} and {\end{center}}


This means that the text should be centered and made to large size.

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.


The text given within \begin{itemize} and \end{itemize}

should be

  • converted to large size
  • and centered according to our definition


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
  • newenvironment
  • newenvironment with parameters
  • renewenvironment


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.


More information on this Mission is available at[1]this[2]link.


This is Ambika Vanchinathan signing off.

Thanks for joining.

Contributors and Content Editors

Ambika, Nancyvarkey