LaTeX/C3/Writing-Style-Files-in-LaTeX/English
Title of script: Writing style file in LaTeX
Author: Arun Rajput
Keywords: style, package, custom, commands, newcommand, renewcommand, environment, newenvironment, renewenvironment, redefine, ubuntu, texworks, LaTeX
Visual Cue | Narration |
Slide : Title | Hello and welcome to the spoken tutorial on “Writing Style files” in LaTeX. |
Slide : Learning Objectives | In this tutorial we will learn how to:
|
Slide : System Requirements | This tutorial is recorded on
The steps demonstrated will work in all operating systems. |
Slide : Pre-requisites |
|
Slide: Code Files |
|
Slide : Style File |
|
Slide : Style File contd. |
|
Slide : Style File contd. |
|
Not on slide, only narration from script | We usually define our own style file in LaTeX to save time and get cleaner code. |
Slide : Style File |
|
Go to Downloads folder >> Stylefile-Code-Files | Go to the folder where all the files are downloaded. |
Double-click the file myPackage.sty | Open the file myPackage.sty in TeXworks editor.
|
Let us try to understand the code. | |
Highlight
|
This newcommand definitionmeans that \iitb is the newcommand.
|
Highlight
\RequirePackage command |
\RequirePackage command is used to load the required packages in the style files. |
Highlight
\RequirePackage{background} |
We are using \RequirePackage{background} for setting the background image. |
Highlight
\newcommand{\iitbbg} |
I have defined \newcommand{\iitbbg} to load IITB’s logo as the background image. |
Highlight
\iitbbg |
So every timeinstead of loading the image manually, we can use \iitbbg command. |
We have now successfully created our custom style file.
| |
Close the file. | Let’s close this file. |
Open the file custom.tex in TeXWorks. | Now open the file custom.tex in TeXworks editor.
|
Highlight
\usepackage{myPackage} |
The new style file is loaded in the preamble using \usepackage command.
|
Highlight
\iitb \iitbbg |
After loading the style file, we use\iitb and \iitbbg commands inside the document section. |
At the top left drop-down >> select pdfLaTeX | At the top left, in the drop-down, select pdfLaTeX if not already selected. |
Click on the green arrow button | Then click on the green arrow button to compile the file. |
Cursor onthe pdf output on the right | On compilation, we get the pdf output on the right.
|
Switch to custom.tex | Come back to custom.tex file.
|
Highlight the pdf output once | But we’re not seeing that in the output. |
Click on the green arrow button |
To display the background image, we may need to compile the code once again.
|
Circle the cursor on the pdf output once | And here is the background image! |
Sometimes, we have to compile the LaTeX code twice, if we don’t see the expected output. | |
Slide: Defining standard style file | Now let’s modify our style file into a standard style file.
|
Slide: Defining standard style file contd.
|
The structure of the style file can be summarized into 3 parts:
|
Slide: Defining standard style file contd. | More information on this guideline is available at this link |
Go to the folder Stylefile-Code-Files | Go to the folder where the code files are saved. |
[TeXworks] myStdPackage.sty | Let’s open the file myStdPackage.sty in TeXworks. |
Highlight the definition | We have written some definition insideour style file.
|
Highlight
NeedsTeXFormat{} |
NeedsTeXFormat{} is used to specify the version of LaTeX in which this style file will work.
|
Highlight
|
ProvidesPackage is used for identification of the package.
|
Highlight.
contents = {\includegraphics[width = \paperwidth, height = \paperheight, keepaspectratio] {iitblogo.pdf}}}} |
From here onwards, we define our commands and definitions.
|
Highlight
\endinput |
\endinput must be the last command in this file.
|
Only narration | Now we have modified our style file into a standard style file. |
Switch to custom.tex. | Next let’s switch back tothe LaTeX file custom.tex. |
Highlight \usepackage{myStdPackage} | In the usepackage command change the package name to myStdPackage. |
Ctrl+S keys >> Click on the green arrow button | Then save andcompile the file. |
Point to the PDF output | We get the same pdf output without any error.
|
Slide: Sharing .sty with Community | Once we have created our own style file, we can share this with the LaTeX community too.
|
This brings us to the end of this tutorial.
| |
Slide: Summary | In this tutorial we learnt *Write a custom style file
|
slide: Assignment | As an assignment:*Identify and make a list of different scenarios where creating a style file would be helpful.
|
Slide: About Spoken Tutorial project | The video at the following link summarises the Spoken Tutorial project.
|
Slide: Spoken Tutorial workshops | The Spoken Tutorial Project Team conducts workshopsand
gives certificates.
|
Slide: Forum | Please post your timed queries in this forum |
Slide:Acknowledgement | Spoken Tutorial Project is funded by MHRD, Government of India.
More information on this Mission is available at this link. |
Slide: Thanks Slide | The script is contributed by Arun, FOSSEE Summer Fellow 2019
|