Difference between revisions of "LaTeX/C3/Writing-Style-Files-in-LaTeX/English"
Pravin1389 (Talk | contribs) (Created page with "'''Title of script''': Writing style file in LaTeX '''Author: Arun Rajput''' '''Keywords: style, package, custom, commands, newcommand, renewcommand, environment, newenviron...") |
Pravin1389 (Talk | contribs) |
||
Line 12: | Line 12: | ||
|| '''Narration''' | || '''Narration''' | ||
|- | |- | ||
− | ||Slide : | + | ||Slide: Title |
||Hello and welcome to the spoken tutorial on “'''Writing''' '''Style files”''' in '''LaTeX.''' | ||Hello and welcome to the spoken tutorial on “'''Writing''' '''Style files”''' in '''LaTeX.''' | ||
|- | |- | ||
− | || Slide : | + | || Slide: Learning Objectives |
|| In this tutorial we will learn how to: | || In this tutorial we will learn how to: | ||
Line 21: | Line 21: | ||
*Import a custom '''style file''' in a '''LaTeX''' document and | *Import a custom '''style file''' in a '''LaTeX''' document and | ||
*Define a '''standard style file''' | *Define a '''standard style file''' | ||
− | |||
− | |||
|- | |- | ||
− | ||Slide : | + | ||Slide: System Requirements |
|| This tutorial is recorded on | || This tutorial is recorded on | ||
Line 32: | Line 30: | ||
The steps demonstrated will work in all operating systems. | The steps demonstrated will work in all operating systems. | ||
|- | |- | ||
− | ||Slide : | + | ||Slide: Pre-requisites |
|| | || | ||
Line 38: | Line 36: | ||
*You should also know how to define '''newcommand''' and '''newenvironment''' in '''LaTeX.''' | *You should also know how to define '''newcommand''' and '''newenvironment''' in '''LaTeX.''' | ||
*If not, then go through the prerequisite '''LaTeX''' spoken tutorials on this website. | *If not, then go through the prerequisite '''LaTeX''' spoken tutorials on this website. | ||
− | |||
− | |||
|- | |- | ||
− | || Slide: | + | || Slide: Code Files |
|| | || | ||
Line 47: | Line 43: | ||
*Please download and use them while practising. | *Please download and use them while practising. | ||
*Make sure that all the supporting files are kept in the same folder while practising. | *Make sure that all the supporting files are kept in the same folder while practising. | ||
− | |||
− | |||
|- | |- | ||
− | ||Slide : | + | || Slide: Style File |
|| | || | ||
*'''Style files '''are also known as '''Packages.''' | *'''Style files '''are also known as '''Packages.''' | ||
*These are supplementary files that increase the functionality of '''LaTeX'''. | *These are supplementary files that increase the functionality of '''LaTeX'''. | ||
− | |||
− | |||
|- | |- | ||
− | || Slide : | + | || Slide: Style File contd. |
|| | || | ||
*You might have used various '''packages''' in your '''LaTeX''' document earlier. | *You might have used various '''packages''' in your '''LaTeX''' document earlier. | ||
*For example, we import '''geometry package''' for defining margin. | *For example, we import '''geometry package''' for defining margin. | ||
− | |||
− | |||
|- | |- | ||
− | ||Slide : | + | ||Slide: Style File contd. |
|| | || | ||
*To reuse the same code many times in the same document, we use''' newcommand '''and '''newenvironment.''' | *To reuse the same code many times in the same document, we use''' newcommand '''and '''newenvironment.''' | ||
*To reuse the same code many times in many documents, we use '''style files'''. | *To reuse the same code many times in many documents, we use '''style files'''. | ||
− | |||
− | |||
|- | |- | ||
|| Not on slide, only narration from script | || Not on slide, only narration from script | ||
|| We usually define our own '''style file''' in '''LaTeX''' to save time and get cleaner code. | || We usually define our own '''style file''' in '''LaTeX''' to save time and get cleaner code. | ||
|- | |- | ||
− | || Slide : | + | || Slide: Style File |
|| | || | ||
*The '''tex''' file containing the content will remain clean, if the '''styles''' are in separate '''sty files'''. | *The '''tex''' file containing the content will remain clean, if the '''styles''' are in separate '''sty files'''. | ||
*Hence, it is advised to write and use '''style files'''. | *Hence, it is advised to write and use '''style files'''. | ||
− | |||
− | |||
|- | |- | ||
|| Go to '''Downloads''' folder >> '''Stylefile-Code-Files''' | || Go to '''Downloads''' folder >> '''Stylefile-Code-Files''' | ||
Line 90: | Line 76: | ||
|| Double-click the file '''myPackage.sty''' | || Double-click the file '''myPackage.sty''' | ||
|| Open the file '''myPackage.sty''' in '''TeXworks '''editor'''.''' | || Open the file '''myPackage.sty''' in '''TeXworks '''editor'''.''' | ||
− | |||
We will see some '''LaTeX '''code written in the file. | We will see some '''LaTeX '''code written in the file. | ||
Line 98: | Line 83: | ||
|- | |- | ||
|| Highlight | || Highlight | ||
− | + | '''\newcommand{\iitb}{\textbf{Indian Institute''' | |
− | + | ''' of Technology – Bombay}}''' | |
− | '''\newcommand{\iitb}{\textbf{Indian Institute of Technology – Bombay}}''' | + | |
|| This '''newcommand '''definitionmeans that '''\iitb '''is the '''newcommand'''. | || This '''newcommand '''definitionmeans that '''\iitb '''is the '''newcommand'''. | ||
− | |||
Whenever \'''iitb''' is used in a '''LaTeX''' document, it will '''typeset''' the full name of '''IITB''' in bold font. | Whenever \'''iitb''' is used in a '''LaTeX''' document, it will '''typeset''' the full name of '''IITB''' in bold font. | ||
|- | |- | ||
− | || Highlight | + | || Highlight '''\RequirePackage command''' |
− | + | ||
− | '''\RequirePackage command''' | + | |
|| '''\RequirePackage command '''is used to load the required '''packages''' in the '''style files'''. | || '''\RequirePackage command '''is used to load the required '''packages''' in the '''style files'''. | ||
|- | |- | ||
− | || Highlight | + | || Highlight \'''RequirePackage{background}''' |
− | + | ||
− | \'''RequirePackage{background}''' | + | |
|| We are using \'''RequirePackage{background} '''for setting the background image. | || We are using \'''RequirePackage{background} '''for setting the background image. | ||
|- | |- | ||
− | || Highlight | + | || Highlight '''\newcommand{\iitbbg}''' |
− | + | ||
− | '''\newcommand{\iitbbg}''' | + | |
||I have defined '''\newcommand{\iitbbg} '''to load '''IITB’s logo''' as the background image. | ||I have defined '''\newcommand{\iitbbg} '''to load '''IITB’s logo''' as the background image. | ||
|- | |- | ||
− | || Highlight | + | || Highlight '''\iitbbg''' |
− | + | ||
− | '''\iitbbg''' | + | |
||So every timeinstead of loading the image manually, we can use '''\iitbbg''' '''command.''' | ||So every timeinstead of loading the image manually, we can use '''\iitbbg''' '''command.''' | ||
|- | |- | ||
|| | || | ||
||We have now successfully created our custom '''style file'''. | ||We have now successfully created our custom '''style file'''. | ||
− | |||
Next let us see how to use this '''style file.''' | Next let us see how to use this '''style file.''' | ||
− | |||
Please note that we do not '''compile .sty files.''' | Please note that we do not '''compile .sty files.''' | ||
Line 140: | Line 113: | ||
|| Open the file''' custom.tex '''in''' TeXWorks.''' | || Open the file''' custom.tex '''in''' TeXWorks.''' | ||
|| Now open the file''' custom.tex '''in''' TeXworks '''editor'''.''' | || Now open the file''' custom.tex '''in''' TeXworks '''editor'''.''' | ||
− | |||
− | |||
− | |||
|- | |- | ||
|| Highlight | || Highlight | ||
Line 148: | Line 118: | ||
'''\usepackage{myPackage}''' | '''\usepackage{myPackage}''' | ||
|| The new '''style file '''is loaded in the preamble using''' \usepackage command'''. | || The new '''style file '''is loaded in the preamble using''' \usepackage command'''. | ||
− | |||
In our example, we have loaded our '''style filemyPackage.''' | In our example, we have loaded our '''style filemyPackage.''' | ||
|- | |- | ||
− | || Highlight | + | || Highlight '''\iitb \iitbbg''' |
− | + | ||
− | '''\iitb \iitbbg''' | + | |
||After loading the '''style file''', we use\'''iitb''' and''' \iitbbg commands''' inside the '''document''' section. | ||After loading the '''style file''', we use\'''iitb''' and''' \iitbbg commands''' inside the '''document''' section. | ||
|- | |- | ||
Line 165: | Line 132: | ||
|| Cursor onthe '''pdf '''output on the right | || Cursor onthe '''pdf '''output on the right | ||
||On compilation, we get the '''pdf '''output on the right. | ||On compilation, we get the '''pdf '''output on the right. | ||
− | |||
Observe the full name of '''IITB''' in the '''PDF'''. | Observe the full name of '''IITB''' in the '''PDF'''. | ||
Line 171: | Line 137: | ||
|| Switch to '''custom.tex''' | || Switch to '''custom.tex''' | ||
|| Come back to '''custom.tex '''file. | || Come back to '''custom.tex '''file. | ||
− | |||
Here, we had included the '''command \iitbbg '''to display the background image. | Here, we had included the '''command \iitbbg '''to display the background image. | ||
Line 182: | Line 147: | ||
Click on the green arrow button | Click on the green arrow button | ||
|| To display the background image, we may need to '''compile''' the code once again. | || To display the background image, we may need to '''compile''' the code once again. | ||
− | |||
Let us '''compile''' it again. | Let us '''compile''' it again. | ||
Line 194: | Line 158: | ||
|| Slide: Defining standard style file | || Slide: Defining standard style file | ||
||Now let’s modify our''' style file''' into a '''standard style file'''. | ||Now let’s modify our''' style file''' into a '''standard style file'''. | ||
− | |||
The reason is,in the real-world you would want to share your '''style file''' with others. | The reason is,in the real-world you would want to share your '''style file''' with others. | ||
− | |||
Ideally, it must adhere to the '''style file''' guidelines given by the '''LaTeX''' community. | Ideally, it must adhere to the '''style file''' guidelines given by the '''LaTeX''' community. | ||
|- | |- | ||
|| Slide: Defining standard style file contd. | || Slide: Defining standard style file contd. | ||
− | |||
− | |||
− | |||
|| The structure of the '''style file''' can be summarized into 3 parts: | || The structure of the '''style file''' can be summarized into 3 parts: | ||
Line 210: | Line 169: | ||
*'''Preliminary declarations''', includes details of the required '''package''' and | *'''Preliminary declarations''', includes details of the required '''package''' and | ||
*'''User code'''. | *'''User code'''. | ||
− | |||
− | |||
|- | |- | ||
|| Slide: Defining standard style file contd. | || Slide: Defining standard style file contd. | ||
Line 226: | Line 183: | ||
|| Highlight the definition | || Highlight the definition | ||
||We have written some '''definition''' insideour '''style file'''. | ||We have written some '''definition''' insideour '''style file'''. | ||
− | |||
Let’s try to understand the code. | Let’s try to understand the code. | ||
Line 234: | Line 190: | ||
'''NeedsTeXFormat{}''' | '''NeedsTeXFormat{}''' | ||
||'''NeedsTeXFormat{} '''is used to specify the version of '''LaTeX''' in which this''' style file''' will work. | ||'''NeedsTeXFormat{} '''is used to specify the version of '''LaTeX''' in which this''' style file''' will work. | ||
− | |||
In our exampleit is '''LaTeX2e.''' | In our exampleit is '''LaTeX2e.''' | ||
|- | |- | ||
− | || Highlight | + | || Highlight |
− | + | '''\ProvidesPackage{myStdPackage}[2019/03/''' | |
− | + | ||
− | '''\ProvidesPackage{myStdPackage}[2019/03/ | + | |
+ | '''11 v0.01 LaTeX package for my own purpose]''' | ||
Highlight the '''''filename''''' in the '''titlebar''' | Highlight the '''''filename''''' in the '''titlebar''' | ||
||'''ProvidesPackage''' is used for identification of the '''package'''. | ||'''ProvidesPackage''' is used for identification of the '''package'''. | ||
− | |||
The '''package''' name should be identical to the '''''filename'''.'' | The '''package''' name should be identical to the '''''filename'''.'' | ||
− | |||
Here I am using'''myStdPackage '''as a parameter and file name. | Here I am using'''myStdPackage '''as a parameter and file name. | ||
− | |||
We willalso provide other details like release date and description of the '''package'''. | We willalso provide other details like release date and description of the '''package'''. | ||
|- | |- | ||
|| Highlight. | || Highlight. | ||
− | |||
'''\newcommand{\iitb}{\textbf{Indian Institute of Technology - Bombay}}''' | '''\newcommand{\iitb}{\textbf{Indian Institute of Technology - Bombay}}''' | ||
− | |||
'''\newcommand{\iitbbg}{\backgroundsetup{scale = 1, angle = 0, opacity = 0.1,''' | '''\newcommand{\iitbbg}{\backgroundsetup{scale = 1, angle = 0, opacity = 0.1,''' | ||
Line 268: | Line 217: | ||
'''height = \paperheight, keepaspectratio] {iitblogo.pdf}}}}''' | '''height = \paperheight, keepaspectratio] {iitblogo.pdf}}}}''' | ||
||From here onwards, we define our '''commands''' and '''definitions'''. | ||From here onwards, we define our '''commands''' and '''definitions'''. | ||
− | |||
Recall, we have used this code in '''myPackage.sty file.''' | Recall, we have used this code in '''myPackage.sty file.''' | ||
− | |||
− | |||
− | |||
|- | |- | ||
|| Highlight | || Highlight | ||
Line 279: | Line 224: | ||
\'''endinput''' | \'''endinput''' | ||
||\'''endinput''' must be the last '''command''' in this file. | ||\'''endinput''' must be the last '''command''' in this file. | ||
− | |||
It indicates that the'''style file''' ends here. | It indicates that the'''style file''' ends here. | ||
Line 285: | Line 229: | ||
|| Only narration | || Only narration | ||
|| Now we have modified our''' style file''' into a '''standard style file'''. | || Now we have modified our''' style file''' into a '''standard style file'''. | ||
− | |- | + | |- |
|| Switch to '''custom.tex'''. | || Switch to '''custom.tex'''. | ||
|| Next let’s switch back tothe '''LaTeX '''file''' custom.tex'''. | || Next let’s switch back tothe '''LaTeX '''file''' custom.tex'''. | ||
Line 297: | Line 241: | ||
||Point to the '''PDF''' output | ||Point to the '''PDF''' output | ||
||We get the same '''pdf '''output without any error. | ||We get the same '''pdf '''output without any error. | ||
− | |||
This means our new '''standard stylepackage''' is working correctly. | This means our new '''standard stylepackage''' is working correctly. | ||
|- | |- | ||
− | || Slide: | + | || Slide: Sharing .sty with Community |
|| Once we have created our own style file, we can share this with the '''LaTeX community''' too. | || Once we have created our own style file, we can share this with the '''LaTeX community''' too. | ||
− | |||
*Upload the created '''style file''' on the '''Comprehensive TeX Archive Network''' | *Upload the created '''style file''' on the '''Comprehensive TeX Archive Network''' | ||
*Provide proper '''documentation''' and read the guidelines before uploading. | *Provide proper '''documentation''' and read the guidelines before uploading. | ||
− | |||
− | |||
|- | |- | ||
|| | || | ||
|| This brings us to the end of this tutorial. | || This brings us to the end of this tutorial. | ||
− | |||
Let us summarise. | Let us summarise. | ||
|- | |- | ||
− | ||Slide: | + | ||Slide: Summary |
− | || In this tutorial we learnt *Write a custom '''style file''' | + | || In this tutorial we learnt |
+ | |||
+ | *Write a custom '''style file''' | ||
*Import the custom '''style file '''in a '''LaTeX '''document | *Import the custom '''style file '''in a '''LaTeX '''document | ||
*Define a '''standard style file''' | *Define a '''standard style file''' | ||
− | |||
− | |||
|- | |- | ||
− | ||slide: | + | ||slide: Assignment |
− | || As an 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 | || Slide: About Spoken Tutorial project | ||
|| The video at the following link summarises the Spoken Tutorial project. | || The video at the following link summarises the Spoken Tutorial project. | ||
− | |||
Please watch it. | Please watch it. | ||
|- | |- | ||
|| Slide: Spoken Tutorial workshops | || Slide: Spoken Tutorial workshops | ||
− | || The Spoken Tutorial Project Team conducts | + | || The Spoken Tutorial Project Team conducts workshops and gives certificates. |
− | + | ||
− | gives certificates. | + | |
− | + | ||
For more details, please write to us. | For more details, please write to us. | ||
Line 345: | Line 280: | ||
|| Please post your timed queries in this forum | || Please post your timed queries in this forum | ||
|- | |- | ||
− | || Slide:Acknowledgement | + | || Slide: Acknowledgement |
|| Spoken Tutorial Project is funded by MHRD, Government of India. | || Spoken Tutorial Project is funded by MHRD, Government of India. | ||
Line 352: | Line 287: | ||
|| Slide: Thanks Slide | || Slide: Thanks Slide | ||
|| The script is contributed by Arun, FOSSEE Summer Fellow 2019 | || The script is contributed by Arun, FOSSEE Summer Fellow 2019 | ||
− | |||
And this is Praveen from IIT Bombay signing off. | And this is Praveen from IIT Bombay signing off. | ||
− | |||
Thanks for joining. | Thanks for joining. | ||
|- | |- | ||
|} | |} |
Revision as of 11:02, 17 December 2019
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.
We will see some LaTeX code written in the file. |
Let us try to understand the code. | |
Highlight
\newcommand{\iitb}{\textbf{Indian Institute of Technology – Bombay}} |
This newcommand definitionmeans that \iitb is the newcommand.
Whenever \iitb is used in a LaTeX document, it will typeset the full name of IITB in bold font. |
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.
Next let us see how to use this style file. Please note that we do not compile .sty files. | |
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.
In our example, we have loaded our style filemyPackage. |
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.
Observe the full name of IITB in the PDF. |
Switch to custom.tex | Come back to custom.tex file.
Here, we had included the command \iitbbg to display the background image. |
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.
Let us compile it 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.
The reason is,in the real-world you would want to share your style file with others. Ideally, it must adhere to the style file guidelines given by the LaTeX community. |
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.
Let’s try to understand the code. |
Highlight
NeedsTeXFormat{} |
NeedsTeXFormat{} is used to specify the version of LaTeX in which this style file will work.
In our exampleit is LaTeX2e. |
Highlight
\ProvidesPackage{myStdPackage}[2019/03/ 11 v0.01 LaTeX package for my own purpose] Highlight the filename in the titlebar |
ProvidesPackage is used for identification of the package.
The package name should be identical to the filename. Here I am usingmyStdPackage as a parameter and file name. We willalso provide other details like release date and description of the package. |
Highlight.
\newcommand{\iitb}{\textbf{Indian Institute of Technology - Bombay}} \newcommand{\iitbbg}{\backgroundsetup{scale = 1, angle = 0, opacity = 0.1, contents = {\includegraphics[width = \paperwidth, height = \paperheight, keepaspectratio] {iitblogo.pdf}}}} |
From here onwards, we define our commands and definitions.
Recall, we have used this code in myPackage.sty file. |
Highlight
\endinput |
\endinput must be the last command in this file.
It indicates that thestyle file ends here. |
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.
This means our new standard stylepackage is working correctly. |
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.
Let us summarise. | |
Slide: Summary | In this tutorial we learnt
|
slide: Assignment | As an assignment:
|
Slide: About Spoken Tutorial project | The video at the following link summarises the Spoken Tutorial project.
Please watch it. |
Slide: Spoken Tutorial workshops | The Spoken Tutorial Project Team conducts workshops and gives certificates.
For more details, please write to us. |
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
And this is Praveen from IIT Bombay signing off. Thanks for joining. |