LaTeX/C3/Writing-Style-Files-in-LaTeX/English-timed
From Script | Spoken-Tutorial
Revision as of 14:59, 6 September 2022 by PoojaMoolya (Talk | contribs)
| Time | Narration |
| 00:01 | Hello and welcome to the spoken tutorial on “Writing Style files” in LaTeX. |
| 00:08 | In this tutorial we will learn how to: |
| 00:11 | Write a custom style file |
| 00:14 | Import a custom style file in a LaTeX document and |
| 00:19 | Define a standard style file |
| 00:23 | This tutorial is recorded on
Ubuntu Linux 18.04 OS and TeXworks Editor v0.6. |
| 00:36 | The steps demonstrated will work in all operating systems. |
| 00:41 | To practise this tutorial, you should be familiar with LaTeX commands. |
| 00:47 | You should also know how to define newcommand and newenvironment in LaTeX. |
| 00:54 | If not, then go through the prerequisite LaTeX spoken tutorials on this website. |
| 01:01 | The files used in this tutorial are available in the Code Files link on this tutorial page. |
| 01:08 | Please download and use them while practising. |
| 01:12 | Make sure that all the supporting files are kept in the same folder while practising. |
| 01:19 | Style files are also known as Packages. |
| 01:23 | These are supplementary files that increase the functionality of LaTeX. |
| 01:29 | You might have used various packages in your LaTeX document earlier. |
| 01:34 | For example, we import geometry package for defining margin. |
| 01:40 | To reuse the same code many times in the same document, we use newcommand and newenvironment. |
| 01:48 | To reuse the same code many times in many documents, we use style files. |
| 01:55 | We usually define our own style file in LaTeX to save time and get cleaner code. |
| 02:03 | The tex file containing the content will remain clean, if the styles are in separate sty files. |
| 02:12 | Hence, it is advised to write and use style files. |
| 02:17 | Go to the folder where all the files are downloaded. |
| 02:21 | Open the file myPackage.sty in TeXworks editor. |
| 02:27 | We will see some LaTeX code written in the file. |
| 02:31 | Let us try to understand the code. |
| 02:34 | This newcommand definition means that slash iitb is the newcommand. |
| 02:40 | Whenever slash iitb is used in a LaTeX document, it will typeset the full name of IITB in bold font. |
| 02:50 | RequirePackage command is used to load the required packages in the style files. |
| 02:57 | We are using RequirePackage background for setting the background image. |
| 03:03 | I have defined newcommand slash iitbbg to load IITB’s logo as the background image. |
| 03:12 | So every time instead of loading the image manually, we can use slash iitbbg command. |
| 03:21 | We have now successfully created our custom style file. |
| 03:25 | Next let us see how to use this style file. |
| 03:30 | Please note that we do not compile .sty files. |
| 03:34 | Let’s close this file. |
| 03:38 | Now open the file custom.tex in TeXworks editor. |
| 03:44 | The new style file is loaded in the preamble using usepackage command. |
| 03:51 | In our example, we have loaded our style filemyPackage. |
| 03:57 | After loading the style file, we use\iitb and \iitbbg commands inside the document section. |
| 04:08 | At the top left, in the drop-down, select pdfLaTeX if not already selected. |
| 04:15 | Then click on the green arrow button to compile the file. |
| 04:20 | On compilation, we get the pdf output on the right. |
| 04:25 | Come back to custom.tex file. |
| 04:29 | Here, we had included the command slash iitbbg to display the background image. |
| 04:37 | But we’re not seeing that in the output. |
| 04:41 | To display the background image, we may need to compile the code once again.
Let us compile it once again. |
| 04:50 | And here is the background image! |
| 04:53 | Sometimes, we have to compile the LaTeX code twice, if we don’t see the expected output. |
| 05:00 | Now let’s modify our style file into a standard style file. |
| 05:06 | The reason is, in the real-world you would want to share your style file with others. |
| 05:13 | Ideally, it must adhere to the style file guidelines given by the LaTeX community. |
| 05:20 | The structure of the style file can be summarized into 3 parts: |
| 05:26 | Identification, includes package name and version |
| 05:32 | Preliminary declarations, includes details of the required package and User code. |
| 05:42 | More information on this guideline is available at this link |
| 05:48 | Go to the folder where the code files are saved. |
| 05:53 | Let’s open the file myStdPackage.sty in TeXworks. |
| 06:01 | We have written some definition inside our style file.
Let’s try to understand the code. |
| 06:09 | NeedsTeXFormat{} is used to specify the version of LaTeX in which this style file will work. |
| 06:17 | In our example, it is LaTeX2e. |
| 06:22 | ProvidesPackage is used for identification of the package. |
| 06:27 | The package name should be identical to the filename. |
| 06:32 | Here I am using myStdPackage as a parameter and file name. |
| 06:39 | We willalso provide other details like release date and description of the package. |
| 06:46 | From here onwards, we define our commands and definitions. |
| 06:51 | Recall, we have used this code in myPackage.sty file. |
| 06:58 | endinput must be the last command in this file. |
| 07:02 | It indicates that the style file ends here. |
| 07:07 | Now we have modified our style file into a standard style file. |
| 07:13 | Next let’s switch back to the LaTeX file custom.tex. |
| 07:19 | In the usepackage command change the package name to myStdPackage. |
| 07:27 | Then save and compile the file. |
| 07:31 | We get the same pdf output without any error. |
| 07:36 | This means our new standard stylepackage is working correctly. |
| 07:42 | Once we have created our own style file, we can share this with the LaTeX community too. |
| 07:49 | Upload the created style file on the Comprehensive TeX Archive Network |
| 07:56 | Provide proper documentation and read the guidelines before uploading. |
| 08:02 | This brings us to the end of this tutorial.
Let us summarise. |
| 08:08 | In this tutorial we learnt
Write a custom style file |
| 08:13 | Import the custom style file in a LaTeX document |
| 08:18 | Define a standard style file |
| 08:22 | As an assignment:
Identify and make a list of different scenarios where creating a style file would be helpful. |
| 08:31 | The video at the following link summarises the Spoken Tutorial project.
Please watch it. |
| 08:39 | The Spoken Tutorial Project Team conducts workshops and gives certificates.
For more details, please write to us. |
| 08:49 | Please post your timed queries in this forum |
| 08:53 | Spoken Tutorial Project is funded by MHRD, Government of India. |
| 08:59 | The script is contributed by Arun, FOSSEE Summer Fellow 2019
And this is Praveen from IIT Bombay signing off. Thanks for joining. |