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

From Script | Spoken-Tutorial
Jump to: navigation, search
m
 
(2 intermediate revisions by 2 users not shown)
Line 13: Line 13:
 
|-
 
|-
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Slide
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Slide
| style="border:0.75pt solid #000000;padding:0.176cm;"| Welcome to the spoken tutorial on creating new '''environments '''in '''LaTeX'''.
+
| style="border:0.75pt solid #000000;padding:0.176cm;"| Welcome to the spoken tutorial on creating '''new environments '''in '''LaTeX'''.
  
 
|-
 
|-
Line 21: Line 21:
 
* create or define new '''environments''' to get customized output.  
 
* create or define new '''environments''' to get customized output.  
 
* redefine the existing '''environments'''.
 
* redefine the existing '''environments'''.
 
 
  
 
|-
 
|-
Line 31: Line 29:
 
# You should also have knowledge of '''compiling '''and producing a '''PDF output '''in '''LaTeX'''.
 
# You should also have knowledge of '''compiling '''and producing a '''PDF output '''in '''LaTeX'''.
 
# If not, please go through the relevant '''LaTeX''' spoken tutorials on this website.
 
# If not, please go through the relevant '''LaTeX''' spoken tutorials on this website.
 
 
  
 
|-
 
|-
Line 40: Line 36:
 
* '''Ubuntu Linux 14.04''' operating system
 
* '''Ubuntu Linux 14.04''' operating system
 
* '''TeXWorks 0.5'''
 
* '''TeXWorks 0.5'''
 
 
  
 
|-
 
|-
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| slide: '''New Environment'''
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| slide: '''New Environment'''
| style="border:0.75pt solid #000000;padding:0.176cm;"| Just like new '''commands,''' we can define new '''environments.'''
+
| style="border:0.75pt solid #000000;padding:0.176cm;"| Just like '''new commands,''' we can define '''new environments.'''
  
  
Line 55: Line 49:
 
|-
 
|-
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| slide: '''New Environment'''
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| slide: '''New Environment'''
| style="border:0.75pt solid #000000;padding:0.176cm;"| New environment is a variation of executing few existing commands put together in a sequence.
+
| style="border:0.75pt solid #000000;padding:0.176cm;"| '''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'''.
+
Ensure that the custom '''environment''' you create, is not an already existing '''LaTeX environment'''.
  
 
|-
 
|-
Line 67: Line 61:
  
  
Here the '''start commands''' are done whenever the environment starts.
+
Here the '''start commands''' are executed whenever the environment starts.
 
+
And '''end commands''' are performed whenever the environment ends.
+
 
+
 
+
  
 +
And '''end commands''' are executed whenever the environment ends.
  
 
|-
 
|-
Line 82: Line 73:
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Pause the tutorial at this point.
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Pause the tutorial at this point.
  
Download and unzip the files provided in the
+
Download and unzip the files provided in the '''Code Files''' link below the player.
 
+
Code Files link below the player.
+
  
 
|-
 
|-
Line 91: Line 80:
  
  
| style="border:0.75pt solid #000000;padding:0.176cm;"| You will see some LaTeX
+
| style="border:0.75pt solid #000000;padding:0.176cm;"| You will see some '''LaTeX
  
code given in the file newEnv.tex
+
code''' given in the file '''newEnv.tex'''
  
 
|-
 
|-
Line 124: Line 113:
  
 
\end{document}
 
\end{document}
| 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;"| We will copy and paste the first block of code from this file into our newly opened '''tex''' file.
  
  
Line 167: Line 156:
 
|-
 
|-
 
| style="border:0.75pt solid #000000;padding:0.176cm;"|  
 
| style="border:0.75pt solid #000000;padding:0.176cm;"|  
| style="border:0.75pt solid #000000;padding:0.176cm;"| We will now see how to use '''parameters''' in the '''environments'''.
+
| style="border:0.75pt solid #000000;padding:0.176cm;"| Now, we will see how to use '''parameters''' in the '''environments'''.
  
 
|-
 
|-
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| slide: '''New environment with parameters'''
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| slide: '''New environment with parameters'''
| style="border:0.75pt solid #000000;padding:0.176cm;"| New environment with parameter is defined as
+
| style="border:0.75pt solid #000000;padding:0.176cm;"| '''New environment''' with parameter is defined as
  
 
'''<nowiki>\newenvironment{environment name}[parameters]{start commands}{end commands} </nowiki>'''
 
'''<nowiki>\newenvironment{environment name}[parameters]{start commands}{end commands} </nowiki>'''
 
 
 
  
 
|-
 
|-
Line 219: Line 205:
  
 
\end{document}
 
\end{document}
| style="border:0.75pt solid #000000;padding:0.176cm;"| Now, we will copy the next block of code from our downloaded
+
| style="border:0.75pt solid #000000;padding:0.176cm;"| We will copy the next block of code from our downloaded code file
  
code file and paste it into our new teX file.
+
 
 +
and paste it into our new '''teX''' file.
  
  
Line 246: Line 233:
 
|-
 
|-
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Point to the exact line as per narration
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Point to the exact line as per narration
| style="border:0.75pt solid #000000;padding:0.176cm;"| * We use it as '''“\begin{bluetext}{My text in blue}”'''
+
| style="border:0.75pt solid #000000;padding:0.176cm;"|  
 +
* We use it as '''“\begin{bluetext}{My text in blue}”'''
 
* and the text,  
 
* and the text,  
 
* and then '''“\end{bluetext}”'''
 
* and then '''“\end{bluetext}”'''
 
 
  
 
|-
 
|-
Line 281: Line 267:
  
  
It’s quite similar to newcommand.
+
It’s quite similar to '''newenvironment'''.
  
 
|-
 
|-
Line 311: Line 297:
  
 
\end{document}
 
\end{document}
| 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.
+
| 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.
  
  
Line 321: Line 307:
  
  
'''\renewcommand{itemize} '''redefines the '''itemize environment.'''
+
'''\renewenvironment{itemize} '''redefines the '''itemize environment.'''
  
  
Line 338: Line 324:
  
  
The text given within '''\begin{itemize}''' and''' \end{itemize}'''
+
The text given within '''\begin{itemize}''' and''' \end{itemize}''' should be  
 
+
should be  
+
  
 
* converted to large size  
 
* converted to large size  
 
* and centered according to our definition
 
* and centered according to our definition
 
 
  
 
|-
 
|-
Line 363: Line 345:
 
* '''renewenvironment'''
 
* '''renewenvironment'''
  
 +
|-
 +
| style="border:0.75pt solid #000000;padding:0.176cm;"| slide: '''Assignment'''
 +
| style="border:0.75pt solid #000000;padding:0.176cm;"| Create an environment '''itemizecolor, '''
  
 +
which takes the color (red, blue, yellow, green) as input
  
|-
+
and creates a list in that color.
| style="border:0.75pt solid #000000;padding:0.176cm;"| slide: '''Assignment'''
+
| style="border:0.75pt solid #000000;padding:0.176cm;"| Create an environment '''itemizecolor, '''which takes the color (red, blue, yellow, green) as input and creates a list in that color.
+
  
 
|-
 
|-
Line 387: Line 371:
 
|-
 
|-
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Slide
 
| style="border:0.75pt solid #000000;padding:0.176cm;"| Slide
| style="border:0.75pt solid #000000;padding:0.176cm;"| Spoken Tutorial Project is funded by the NMEICT, MHRD, Government of India.
+
| style="border:0.75pt solid #000000;padding:0.176cm;"| Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
  
  
More information on this Mission is available at[http://spoken-tutorial.org/NMEICT-Intro  ][http://spoken-tutorial.org/NMEICT-Intro this][http://spoken-tutorial.org/NMEICT-Intro  ][http://spoken-tutorial.org/NMEICT-Intro link][http://spoken-tutorial.org/NMEICT-Intro .]
+
More information on this Mission is available at this link.
  
  

Latest revision as of 20:37, 19 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 executed whenever the environment starts.

And end commands are executed 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>>
Now, we will 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}

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

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.


\renewenvironment{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 NMEICT, MHRD, Government of India.


More information on this Mission is available at this link.


This is Ambika Vanchinathan signing off.

Thanks for joining.

Contributors and Content Editors

Ambika, Nancyvarkey