Difference between revisions of "LaTeX/C3/newenvironment-in-LaTeX/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "'''Title of script: New Environments''' '''Author:''' '''Ambika Vanchinathan''' '''Keywords: New environment, renewenvironment, define environments in LaTeX, \newenvironment...")
 
m
Line 77: Line 77:
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Open the '''TeXWorks''' editor
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Open the '''TeXWorks''' editor
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Let us open the '''TeXWorks''' editor.
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Let us open the '''TeXWorks''' editor.
 +
 +
|-
 +
| style="border:0.75pt solid #000000;padding:0.176cm;"|
 +
| style="border:0.75pt solid #000000;padding:0.176cm;"| Pause the tutorial at this point.
 +
 +
Download and unzip the files provided in the
 +
 +
Code Files link below the player.
 +
 +
|-
 +
| style="border:0.75pt solid #000000;padding:0.176cm;"| Switch to the code file
 +
 +
 +
 +
| style="border:0.75pt solid #000000;padding:0.176cm;"| You will see some LaTeX
 +
 +
code given in the file newEnv.tex
  
 
|-
 
|-
Line 107: Line 124:
  
 
\end{document}
 
\end{document}
| style="border:0.75pt solid #000000;padding:0.176cm;"| Type the code as shown here into the '''tex''' file.
+
| style="border:0.75pt solid #000000;padding:0.176cm;"| We will copy and paste the first block of code from this file into our newly opened tex file.
 +
 
 +
 
 +
 
 +
 
 +
|-
 +
| style="border:0.75pt solid #000000;padding:0.176cm;"|
 +
| style="border:0.75pt solid #000000;padding:0.176cm;"| Let’s try to understand the program.
  
 
|-
 
|-
Line 157: Line 181:
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| open a new file in TeXWorks
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| open a new file in TeXWorks
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Let’s open a new file in '''TeXWorks'''.
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Let’s open a new file in '''TeXWorks'''.
 +
 +
|-
 +
| style="border:0.75pt solid #000000;padding:0.176cm;"| Switch to the code file
 +
| style="border:0.75pt solid #000000;padding:0.176cm;"| Now switch to our downloaded code file.
  
 
|-
 
|-
Line 191: Line 219:
  
 
\end{document}
 
\end{document}
| style="border:0.75pt solid #000000;padding:0.176cm;"| Now, we will copy the code given here into our '''TeX''' file.
+
| style="border:0.75pt solid #000000;padding:0.176cm;"| Now, we will copy the next block of code from our downloaded
 +
 
 +
code file and paste it into our new teX file.
 +
 
 +
 
 +
 
  
 
|-
 
|-
Line 252: Line 285:
 
|-
 
|-
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Open a new '''tex''' file.
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Open a new '''tex''' file.
| style="border:0.75pt solid #000000;padding:0.176cm;"| Open a new '''tex''' file.
+
| style="border:0.75pt solid #000000;padding:0.176cm;"| Once again, we will open a new '''tex''' file.
  
 
|-
 
|-
Line 278: Line 311:
  
 
\end{document}
 
\end{document}
| style="border:0.75pt solid #000000;padding:0.176cm;"| Type the code as given here.
+
| style="border:0.75pt solid #000000;padding:0.176cm;"| We will copy and paste the last block of code from our downloaded file into our newly opened tex file.
 +
 
 +
 
 +
 
  
 
|-
 
|-

Revision as of 13:45, 18 September 2015

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.
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)


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

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


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.
Switch to the code file Now switch to our downloaded code file.
(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 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.


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. Once again, we will 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}

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.


\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