LaTeX forum ⇒ Document ClassesOption [natbib] Declaration

Information and discussion about specific document classes and how to create your own document classes.
Ethan Phan
Posts: 3
Joined: Tue Mar 31, 2015 10:58 am

Option [natbib] Declaration

Postby Ethan Phan » Tue Mar 31, 2015 12:17 pm

Hi everyone,
I'm currently working on building a new class file based on an old one which is my university thesis class. And I am totally new user for such a work.

Here is the code in the old file named "muthesis09.cls"

  1. \NeedsTeXFormat{LaTeX2e}
  2. \ProvidesClass{muthesis09}[2010/04/24 v0.91 Mahidol University thesis class]
  3. \LoadClass[12pt,a4paper]{report}
  4.  
  5. \RequirePackage{times}
  6. \RequirePackage{ifthen}
  7.  
  8. \newboolean{@natbibmode}\setboolean{@natbibmode}{false}
  9. \DeclareOption{natbib}{%
  10. \setboolean{@natbibmode}{true}%
  11. }
  12. \ProcessOptions\relax
  13. \if@natbibmode
  14. \RequirePackage{natbib}% this cannot go inside \DeclareOption argument
  15. \bibpunct{(}{)}{;}{a}{}{,}%
  16. \else
  17. \fi


I think this code is to declare the option @natbibmode, execute, then ask if it is a require package; at last, changing the way of producing the bibliography using a natbib package command \bibpunct.

Now suppose there is a "new way" to achieve the aiming work as listed above---my own code:

  1. \NeedsTeXFormat{LaTeX2e}
  2. \ProvidesClass{muthesis15}[2015/03/09 My custom muthesis]
  3. % below are some packages needed to use:
  4. % package IFTHEN for coding this cls file
  5. \RequirePackage{ifthen}
  6.  
  7. \DeclareOption{natbibmode}
  8. {\newboolean{natbibmode}%
  9. \setboolean{natbibmode}{true}}
  10. \ifthenelse
  11. {\boolean{natbibmode}}
  12. {
  13. \RequirePackage{{natbib}
  14. \bibpunct{(}{)}{;}{a}{}{,}
  15. }
  16. {}
  17. % package NATBIB for using the bibliography enviroment more effective
  18. \PassOptionToClass{report}
  19. % the typesetting thesis will made use of: 12pt (font size), A4 paper;
  20. % and natbib for the bibliography (references)
  21. \LoadClass[12pt,a4paper]{report}


then that raises questions:
  1. Why in the old code the author need to set the false value boolean to @natbibmode? Why didn't he just creat it and then set the value to be true later in the \DeclareOption command? Alternative, why didn't he set it to be true at the time he created that boolean?
  2. From the above questions, I have my own code. Is it right?
  3. What is the difference between \ExecuteOptions and \ProcessOptions commands? Do I need any of them in the above code?
  4. (Side question) Do I need to include the special character @ at the very begining of each command or counter convention name? The reason of this question is, in the file muthesis09, the author then put @ in names of every counter and every command name that made used(!!!), and his action make me headache to classify which one is LaTeX primitive (or TeX primitive) and which one is his code :!:

If possible, please let me know a better code to achieve the aim. Thank you.

Tags:

User avatar
Johannes_B
Site Moderator
Posts: 3584
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Tue Mar 31, 2015 2:39 pm

Hi and welcome,

this is quite a bunch of question you are asking here. In my experience, thesis classes from universities are very very bad maintained. A few weeks back i was confronted with a class that was using some code from the beginnings of LaTeX2e, around 1993.

First of all, though many journals still use the old system of BibTeX in conjunction with packages like natbib, there is a new package on the horizon, called biblatex.


Writing packages and classes is something for experienced users. You should definitely have read LaTeX2e for class and package authors. This will get rid of some of your questions and ensure a stable document.
In current documents, @ is not a letter, and hence the user has to take care to redefine those commands, which is done by the \makeatletter and \makeatother combo.


A completely different approach would be using the new programming interface of LaTeX3.


No matter which way you choose, use some freely accessible repository, on github and the like. This makes contribution by others, in form of bug reports and other issues, as well as suggestions for improbvements, much more easy.


As far as i can tell by a quick look, the code cannot work. The boolean flag for natbib will only be defined, if the option is given. If not, the test for true or false will result in the boolean flag not defined, if natbib-option was not given.
Please also have a look at package etoolbox that makes work with bools easier.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

Ethan Phan
Posts: 3
Joined: Tue Mar 31, 2015 10:58 am

Postby Ethan Phan » Wed Apr 01, 2015 7:18 am

Thank you for your answer and suggestion ( and also, your warm welcome, too :) ), Johannes.
I will read and look up carefully in those you mentioned.
For the CLSGuide, I'm on the way of reading it, but right now I stop a while to read "LaTeX: A Document Preparation System" to understand some `usual concepts', such as moving argument, terminal, robust vs. fragile commands, etc.

User avatar
Stefan Kottwitz
Site Admin
Posts: 8537
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Wed Apr 01, 2015 9:14 am

Hello Ethan,

welcome to the forum!

If you would like to talk about such LaTeX concepts, here is the right place. :-)

Stefan
Site admin

User avatar
Johannes_B
Site Moderator
Posts: 3584
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Wed Apr 01, 2015 12:36 pm

I have to be honest that i never read Leslie Lamports book.

LaTeX is a bit like cars over the years ... Whereas Lamports design was a breakthrough, a lot of advancements and enhancements were made over the years, making some of the stuff he wrote obsolete, thoug still true in principle.


But its great that you keep on hanging with LaTeX.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

User avatar
cgnieder
Site Moderator
Posts: 1974
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Mon Aug 10, 2015 7:29 pm

Ethan Phan wrote:Here is the code in the old file named "muthesis09.cls"

  1. \NeedsTeXFormat{LaTeX2e}
  2. \ProvidesClass{muthesis09}[2010/04/24 v0.91 Mahidol University thesis class]
  3. \LoadClass[12pt,a4paper]{report}
  4.  
  5. \RequirePackage{times}
  6. \RequirePackage{ifthen}
  7.  
  8. \newboolean{@natbibmode}\setboolean{@natbibmode}{false}
  9. \DeclareOption{natbib}{%
  10. \setboolean{@natbibmode}{true}%
  11. }
  12. \ProcessOptions\relax
  13. \if@natbibmode
  14. \RequirePackage{natbib}% this cannot go inside \DeclareOption argument
  15. \bibpunct{(}{)}{;}{a}{}{,}%
  16. \else
  17. \fi


I think this code is to declare the option @natbibmode, execute, then ask if it is a require package; at last, changing the way of producing the bibliography using a natbib package command \bibpunct.


This declares a class option natbib (\DeclareOption{natbib}) which does nothing but setting the boolean flag @natbibmode to true. This flag is defined earlier (\newboolean{@natbibmode}) and set to false (which is redundant at that state because the default state of a boolean is false but it doesn't hurt either). After the options have been processed (\ProcessOptions) the state of the boolean is checked and the package natbib is loaded and \bibpunct is used if the state is true.

Ethan Phan wrote:Now suppose there is a "new way" to achieve the aiming work as listed above---my own code:

  1. \NeedsTeXFormat{LaTeX2e}
  2. \ProvidesClass{muthesis15}[2015/03/09 My custom muthesis]
  3. % below are some packages needed to use:
  4. % package IFTHEN for coding this cls file
  5. \RequirePackage{ifthen}
  6.  
  7. \DeclareOption{natbibmode}
  8. {\newboolean{natbibmode}%
  9. \setboolean{natbibmode}{true}}
  10. \ifthenelse
  11. {\boolean{natbibmode}}
  12. {
  13. \RequirePackage{{natbib}
  14. \bibpunct{(}{)}{;}{a}{}{,}
  15. }
  16. {}
  17. % package NATBIB for using the bibliography enviroment more effective
  18. \PassOptionToClass{report}
  19. % the typesetting thesis will made use of: 12pt (font size), A4 paper;
  20. % and natbib for the bibliography (references)
  21. \LoadClass[12pt,a4paper]{report}


This defines the boolean flag if (and only if) the class option natbibmode is used by the user. I don't know how forgiving the ifthen package and its \ifthenelse command is when tested for an undefined boolean but I'd consider it bad practice. It's probably safe with ifthen (if it is forgiving) since this package is not very likely to get further updates but in other testing methods one might expect an error in such a case.

I'd rather use
  1. \newboolean{natbibmode}
  2. \DeclareOption{natbibmode}{\setboolean{natbibmode}{true}}


Other then that the code looks fine to me.

Ethan Phan wrote:What is the difference between \ExecuteOptions and \ProcessOptions commands? Do I need any of them in the above code?
Is this clear now from LaTeX2e for class and package writers
(clsguide)? Or are there questions left?

Ethan Phan wrote:Do I need to include the special character @ at the very begining of each command or counter convention name? The reason of this question is, in the file muthesis09, the author then put @ in names of every counter and every command name that made used(!!!), and his action make me headache to classify which one is LaTeX primitive (or TeX primitive) and which one is his code :!:
Johannes already said that the usual state (the category code) of @ in a document usually is not “letter” (category code 11) but “other” (category code 12). However, due to how packages and classes are loaded it is a letter in class and package files. It is a broad convention to use it in internal macro names that are not to be used by users (or let's say: not if they don't know what they're doing). Modifying package and class internals thus usually requires \makeatletter (for making @ a “letter”) and \makeatother (for making it “other” again).

Personally I use prefixes for all macros in my packages. For example in my translations package every macro starts with \@trnslt@ except for the user commands.

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim


Return to “Document Classes”

Who is online

Users browsing this forum: No registered users and 5 guests