LaTeX/C3/newcommand-in-LaTeX/English-timed
| Time | Narration |
| 00:02 | Welcome to the spoken tutorial on creating new commands in LaTeX. |
| 00:08 | This tutorial will help the learners to
create or define new commands to get customized output. redefine the existing commands. |
| 00:18 | 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. |
| 00:37 | To record this tutorial, I am using
Ubuntu Linux 14.04 operating system TeXWorks 0.5 |
| 00:47 | We all know that commands are special words that are provided to the compiler. |
| 00:52 | Commands start with a backslash and sometimes accept parameters.
Example: \noindent, \textbf, \centering |
| 01:02 | We can define our own custom commands in LaTeX to save time or for the code to look cleaner. |
| 01:09 | Ensure that the custom command you create is not an already existing LaTeX command. |
| 01:15 | To define a new command, we write \newcommand{command}{definition} at the beginning of the document. |
| 01:27 | Let us open the TeXWorks editor. |
| 01:34 | Pause the tutorial at this point.Download and unzip the files provided in the Code Files link below the player. |
| 01:43 | You will see some LaTeX code given in the file “newComm.tex” that you downloaded onto your machine. |
| 01:59 | We will copy and paste the first block of code from this file into our newly opened tex file. |
| 02:09 | Let’s try to understand the program. |
| 02:12 | The definition \newcommand{\bbr}{\mathbb R} means that \bbr is the newcommand. |
| 02:24 | And when used, it will typeset R in the mathbb font. |
| 02:31 | Note that the required packages are loaded in the preamble; in this case \usepackage{amsfonts} |
| 02:40 | So, instead of {\mathbb R}, we can use \bbr within dollars while typesetting. |
| 02:48 | Let us save the file as newComm.tex |
| 03:00 | On compilation, we get the pdf output. Observe the letter R in mathbb font. |
| 03:15 | Now, we will see newcommand with parameters. |
| 03:24 | It is typically defined as -
'\newcommand{\command}[parameters]{definition} |
| 03:36 | Let’s open a new file in TeXWorks. |
| 03:45 | Now switch to our downloaded code file. |
| 03:59 | We will copy the next block of code from our downloaded code file and paste it into our new teX file. |
| 04:07 | Let us understand the code now. |
| 04:11 | We have \newcommand{\bb}[1]{\mathbb {#1}}before the begin document statement. |
| 04:22 | Here \bb is the command.
|
| 04:30 | \mathbb {#1} defines the command.
#1 means the first parameter. |
| 04:37 | Carefully observe the usage after \begin{document} |
| 04:42 | We use it within dollars because it contains math symbols. |
| 04:48 | \bb followed by the open brace and parameter and again we close the brace. |
| 04:58 | We have used it twice with R as the parameter in the first usage and Z as the parameter in the second usage. |
| 05:08 | Save the program as newCommP1.tex and compile it. |
| 05:28 | In the output, observe that the R and Z are in the mathbb or the blackboard font. |
| 05:40 | Next, let’s define a newcommand with 2 parameters. |
| 05:46 | Open a new tex file. |
| 06:08 | We will copy and paste the next block of code from our downloaded file, as shown here. |
| 06:16 | Observe the line \newcommand{\add}[2]{ \left( #1 + #2 \right) } in the document. |
| 06:34 | This has been used as $\add{abc}{xyz}$ Here in the definition, \add is the newcommand. |
| 06:47 | [2] indicates that it has 2 parameters. {\left( #1+#2\right)} is the definition of the command. |
| 06:57 | #1 for the first parameter and #2 for the second parameter. |
| 07:05 | #1 and #2 are replaced by the actual text {abc} and {xyz} in this case. |
| 07:16 | Let us save as newCommP2.tex and compile the tex file. |
| 07:32 | Observe the output.
Here the left and right parenthesis are added and a plus symbol is introduced between the first and second parameters. |
| 07:53 | Let’s now learn about the renewcommand. |
| 07:59 | renewcommand is used to change or overwrite the existing command. |
| 08:04 | The syntax for renewcommand is \renewcommand{command}{definition} It’s quite similar to newcommand. |
| 08:18 | Once again, we will open a new tex file. |
| 08:35 | We will copy and paste the last block of code from our downloaded file into our newly opened tex file. |
| 08:45 | Let us understand the program now. |
| 08:48 | The definition \renewcommand{\S}{\mathcal {S}} redefines \S. |
| 08:58 | \S normally produces the section symbol (§) |
| 09:02 | whereas after redefining \S, produces S in Calligraphic font |
| 09:11 | Note that the required package amsmath is preloaded. Also, we use \S within dollar symbols. |
| 09:26 | Let us now save the file as renew.tex, compile it and see the output. We can see “S” in calligraphic font. |
| 09:49 | Come back to the tex file. |
| 09:59 | Note that replacing z for S in the renewcommand does not work. |
| 10:06 | This is because there is no existing command defined as \z. |
| 10:12 | Please use renewcommand only when you are very sure about what you are doing. |
| 10:26 | To summarise, we have learnt
newcommand newcommand with parameters renewcommand |
| 10:37 | Assignment
Create a new command \textbfit which will convert the given text into bold and italics. |
| 10:50 | The video at the following link summarises the Spoken Tutorial project.
Pls watch it. |
| 10:57 | The Spoken Tutorial Project Team : Conducts workshops using spoken tutorials and Gives certificates to those who pass an online test |
| 11:07 | For more details, please write to us. |
| 11:11 | Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India. More information on this Mission is available at this link. |
| 11:24 | This is Ambika Vanchinathan signing off. Thanks for joining. |