I downloaded a package from an article template. The thing is that I want to edit it, but don´t know how to do it.
-
Maybe open it in a text editor, make any changes you want, and then save it;)? Or, what about making the question a bit more precise? (Please, don't take any offense - just be more specific.) – mbork Aug 31 '13 at 09:20
-
9It's not clear here if you mean a template to produce a document, a LaTeX package, a class or indeed something else. Could you perhaps give a little more detail, and say for example where we might find the template. – Joseph Wright Aug 31 '13 at 09:27
1 Answers
It depends on what you want to change …
Example
Let’s assume a simple and small package package.sty with the following content. I use this imaginary package since it can contain all things I want to share and doens’t have that complex code. If you want to test it save the package code as package.sty in your document folder, i.e. the same where the text file is saved, or your user texmf tree*.
\ProvidesPackage{package}
\DeclareOption*{No options.}
\ProcessOptions\relax
\RequirePackage{parskip}
\newcounter{counter}
\newlength{\length}
\setlength{\length}{1em}
\newcommand{\numfont}{\sffamily\bfseries}
\newcommand{\pkg@printnumber}[1]{
{\numfont(#1)}%
}
\newcommand*{\numberbox}[1]{%
\par
\refstepcounter{counter}%
\fbox{%
\pkg@printnumber{\thecounter}\hspace{\length}#1%
}%
\par
}
Which is used in a document like this:
\documentclass{article}
\usepackage{package}
\begin{document}
\section{Sec 1}
\numberbox{Foo}
\numberbox{Bar}
\section{Sec 2}
\numberbox{Baz}
\end{document}
Smaller changes
Can be made in your document inside the preamble, i.e. before \begin{document} but after loading the package.
(1) change the definition of some macros
If you want to change the behavior of a macro you can use \renewcommand and set up the new definition or the tools like \patchcmd from etoolbox.
For example if you want to change the font of the numbers use
\renewcommand{\numfont}{\bfseries} % (1.1)
if you want to add something to the definition use \appto from etoolbox
\appto\numfont{\sffamily} % (1.2)
and if you want to replace the part of a command, e.g. replace \numfont with \myfont use \patchcmd. Note that you’ll need \makeatletter** if the macro names containing an @.
\makeatletter
\newcommand{\myfont}{\sffamily\itshape}
\patchcmd{\pkg@printnumber}{\numfont}{\myfont}{}{} % (1.3)
\makeatother
(2) change a length
Use \setlegth to change a length.
\setlength{\length}{2em} % (2.1)
or again \patchcmd to replace it
\newlength{\mylength}\setlength{\mylength}{3em}
\patchcmd{\numberbox}{\length}{\mylength}{}{} % (2.2)
(3) change the appearance of counters
To change the appearance of a counter, e.g. from 1, 2, 3 to I, II, III, change the definition of \the<counter> with \renewcommand, again.
\renewcommand{\thecounter}{\Roman{counter}} % (3.1)
chngcntr has some more tools for this. You can add the section counter, for instance.
\counterwithin{counter}{section} % (3.2)
Full MWE for the above changes
Note that not all changes are visible at once, e.g. (3.2) overwrites (3.1), so you may uncomment some lines to see the effects.
\documentclass{article}
\usepackage{package}
\usepackage{etoolbox}% required by (1.2), (1.3), (2.2)
\usepackage{chngcntr}% required by (3.2)
% (1)
\renewcommand{\numfont}{\bfseries} % (1.1)
\appto\numfont{\sffamily} % (1.2)
\makeatletter
\newcommand{\myfont}{\sffamily\slshape}
\patchcmd{\pkg@printnumber}{\numfont}{\myfont}{}{} % (1.3)
\makeatother
% (2)
\setlength{\length}{2em} % (2.1)
\newlength{\mylength}\setlength{\mylength}{3em}
\patchcmd{\numberbox}{\length}{\mylength}{}{} % (2.2)
% (3)
\renewcommand{\thecounter}{\Roman{counter}} % (3.1)
\counterwithin{counter}{section} % (3.2)
\begin{document}
\section{Sec 1}
\numberbox{Foo}
\numberbox{Bar}
\section{Sec 2}
\numberbox{Baz}
\end{document}
More complex changes
Make a copy of the sty file and save it with a new name in your user texmf tree*. Then open it in your favorite editor and do the changes you want.
* See Where do I place my own .sty or .cls files, to make them available to all my .tex files?, for instance.
** See What do \makeatletter and \makeatother do?.
-
1You mean strongly when you say hardly, right? :) And shouldn't it be
\renewcommand? – cgnieder Aug 31 '13 at 09:23 -
-
1
-
-
A very good answer. I think it could be made even stronger by showing a few examples with actual code. Pick a package a demonstrate for us. – Steven B. Segletes Aug 31 '13 at 12:39
-
you might point out that the first three changes are meant to be made in the preamble of the new document, not in the original
.styfile. should be obvious to a reader, but ... – barbara beeton Aug 31 '13 at 18:11 -
-