Document ClassesHow to make class/package changes apply?

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
benjibloublou
Posts: 6
Joined: Wed Sep 26, 2012 6:56 pm

How to make class/package changes apply?

Post by benjibloublou »

Hello everyone,

I might ask a really silly/noob question but here it goes :oops: :
I have downloaded the moderncv class to have a frame to write my resumé. Yet I don't like the existing styles. I just want to change the color of a few parts.
After modifying the .cls and .sty files, nothing changed. I tried to switch every single color defined in the class (and its .sty extensions) to red. I refreshed the MikTeX database and updated formats, but LaTeX still gives me the same black and white CV.
No error in the log and xcolor is used...

Am I missing something necessary for the changes in a class/package to take effect?

Thank you all,
Cheers,
- B.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

How to make class/package changes apply?

Post by Stefan Kottwitz »

Hi,

welcome to the board!

I strongly recommend: never change .cls or .sty files! Your document would not work the same if you update packages, or you TeX installation, or if you would compile on a different computer. Editing style files or classes is strongly discouraged. At least, you should give it a different file and class name, if you insist on changing.

The normal way is to use class features or LaTeX commands such as \renewcommand to redefine whatever you would like to change. It would be good to read some basic LaTeX introductions or a tutorial, have a look at: LaTeX Resources for Beginners. Also a book about LaTeX could be a good start, instead of just jumping in. It's a good question which you asked, and a very important topic, it just means that may need some further fundamental information about the way LaTeX works. Don't worry, we all started at some time.

Stefan
LaTeX.org admin
benjibloublou
Posts: 6
Joined: Wed Sep 26, 2012 6:56 pm

How to make class/package changes apply?

Post by benjibloublou »

Thank you Stefan.

However, I think I'm quite familiar with LaTeX :) I've been using it frequently for 4 years now. I am also pretty familiar with general programming in several languages so I think I can handle a .cls or .sty modification. Otherwise, how do people do to adapt an existing package to their specific needs? Do they always create a new one from scratch, even if they want really slight changes as I do?

Ok I'm not being aggressive at all! :) I just want to say that I am not modifying random things without understanding it at all. But I'm still missing something. I am going to explain my problem better :
Suppose there's a class called KLASS which defines one specific command : the command \xcommand{abcdef} where "abcdef" has to be the title of the document. KLASS also defines a color called "color0" with \definecolor{color0}{rgb}{0,0,0}. In this case, color0 is pure black. KLASS is written so that "\xcommand{abcdef}" displays with color "color0" in your pdf.
Suppose I just change "\definecolor{color0}{rgb}{0,0,0}" to "\definecolor{color0}{rgb}{1,0,0}" -- that is switching from black to red -- in the .cls file and save it. Shouldn't my title display in red when I use \xcommand within KLASS now?

If there is something else to do for that change to take effect, that's what I want to know.

Thx,
Cheers
Last edited by cgnieder on Wed Sep 26, 2012 10:12 pm, edited 1 time in total.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

How to make class/package changes apply?

Post by cgnieder »

Well, it depends how, where and when the class is doing the definition.

Here an example that works:

Code: Select all

\RequirePackage{filecontents}
\begin{filecontents}{KLASS.cls}
\ProvidesPackage{KLASS}[2012/09/26 0.1 some super-duper class]
\RequirePackage{xcolor}
\definecolor{color0}{rgb}{0,0,0}
\newcommand*\xcommand{\textcolor{color0}{abcdef}}
\LoadClass{article}
\endinput
\end{filecontents}

\documentclass{KLASS}
\definecolor{color0}{rgb}{1,0,0}

\begin{document}

\xcommand

\end{document}
And here another one where it fails:

Code: Select all

\RequirePackage{filecontents}
\begin{filecontents}{KLASS.cls}
\ProvidesPackage{KLASS}[2012/09/26 0.1 some super-duper class]
\RequirePackage{xcolor}
\AtBeginDocument{\definecolor{color0}{rgb}{0,0,0}}
\newcommand*\xcommand{\textcolor{color0}{abcdef}}
\LoadClass{article}
\endinput
\end{filecontents}

\documentclass{KLASS}
\definecolor{color0}{rgb}{1,0,0}

\begin{document}

\xcommand

\end{document}
And a third version that also fails:

Code: Select all

\RequirePackage{filecontents}
\begin{filecontents}{KLASS.cls}
\ProvidesPackage{KLASS}[2012/09/26 0.1 some super-duper class]
\RequirePackage{xcolor}

\newcommand*\xcommand{%
  \begingroup
    \definecolor{color0}{rgb}{0,0,0}%
    \textcolor{color0}{abcdef}%
  \endgroup}
\LoadClass{article}
\endinput
\end{filecontents}

\documentclass{KLASS}
\definecolor{color0}{rgb}{1,0,0}

\begin{document}

\xcommand

\end{document}
That last two cases can be circumvented/redefined/patched (whatever you want to call it) as well but the strategy depends on the case...

Regards
site moderator & package author
benjibloublou
Posts: 6
Joined: Wed Sep 26, 2012 6:56 pm

How to make class/package changes apply?

Post by benjibloublou »

Haha yeah... but there you're always trying to REdefine color0 once the class has been declared. I am talking about changing the initial definition of color0, the one in the class definition, that is the one in the filecontents environment in your example.

In my case, there is now nowhere in the .cls and .sty files where any color is defined to black. I changed all definitions to red. But as the class is pretty complex, I guess it's just that these definitions are ignored in some cases or something. I'll try to figure it out!

Thank you both for your help,
- B.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

How to make class/package changes apply?

Post by cgnieder »

benjibloublou wrote:Haha yeah... but there you're always trying to REdefine color0 once the class has been declared.
Yes of course. Changing a package or class directly is not recommended. (There might by licence problems...) Of course if the license allows you to use the code (as LPPL does) and if you save the changed file under new name all is good :)
benjibloublou wrote:In my case, there is now nowhere in the .cls and .sty files where any color is defined to black. I changed all definitions to red. But as the class is pretty complex, I guess it's just that these definitions are ignored in some cases or something. I'll try to figure it out!
Well, I can't say anything without knowing both the class and what you're changes are so... Good luck anyway :)

Regards
site moderator & package author
benjibloublou
Posts: 6
Joined: Wed Sep 26, 2012 6:56 pm

Re: How to make class/package changes apply?

Post by benjibloublou »

Actually I want to keep talking about that.

I erased several parts of the .cls file. Especially parts where .sty extensions are loaded, definitions are made, and so on. I saved it. I closed my LaTeX editor and updated the MikTeX distribution. I deleted all previously LaTeX-generated pdf and other files. When I run Latex+PDF on my CV, using the moderncv class I totally destroyed, it still produces the perfect PDF file!!! So that means the changes in the .cls file are not taken into account, as if the original version was already loaded somewhere... How do I change that?

I hope this will enable you to better understand what my (very stupid) problem is :D.

Cheers,
- B.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

How to make class/package changes apply?

Post by cgnieder »

My guess would be that in the update process the original file was restored. If it wasn't you have another copy somewhere that is found before your modified one. Have you searched if there is a second file somewhere in your texmf tree?

It would be best, anyway, to save the modified version in a local tree.

Create a local texmf tree in MiKTeX

Regards
site moderator & package author
benjibloublou
Posts: 6
Joined: Wed Sep 26, 2012 6:56 pm

Re: How to make class/package changes apply?

Post by benjibloublou »

You got it! I checked the log file and the class has been copied in another folder. That's this one that LaTeX uses. Everything is now red :D

Thank you!
Post Reply