Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The soul package defines a ton of short macros, some of which I use regularly for my own writing. I only need \hl and \sethlcolor. Is there a way to load the package and only get those two commands?

share|improve this question
    
It would be really cool if packages could export macros like e.g. Perl modules do it. Using options to only define certain macros is possible, but you can't load one package twice with different options. This would be a nice feature for LaTeX3: packages declare sets of non-clashing options and can be loaded multiple times using different combinations of these. –  Martin Scharrer Apr 19 '11 at 10:03
    
@Martin: One obvious part to this is the idea that document commands should be defined independently of internal material. How packages will be handled for LaTeX3 is still a long way off being discussed! –  Joseph Wright Apr 19 '11 at 11:16

2 Answers 2

Some packages allow to select the amount of defined macros using options, but I don't think the soul package provides such.


For very simple packages could be loaded in a group and only the wanted commands could be defined globally. However, this is getting complicated as soon this commands are using internal macros which of course also must be kept defined. The soul package is complex enough to make this a tedious task.

\begingroup
  \usepackage{<package>}
  \global\let\wantedmacro\wantedmacro
  \global\expandafter\let\csname special name\expandafter\endcsname\csname special name\endcsname
  % ...
\endgroup

Also some internal LaTeX macro which are defined for every loaded package must be handled, etc.


A better way would be to either only (re-)define the macros after loading the package, as Alan Munn already stated, or save and restore the macros in question around the \usepackage. This is necessary if the macros would be defined by another package which must be loaded beforehand for some reason.

\let\origsomemacro\somemacro % save the macro 
\let\somemacro\relax         % reset it, so it can be defined using `\newcommand` can be used without error
\usepackage{somepackage}     % load package
\let\altsomemacro\somemacro  % save that macro definition under a different name if required
\let\somemacro\origsomemacro % restore original definition

However, this might cause problems if the package relies on its own definition of these macros.

share|improve this answer
    
if the package relies on its own definition of these macros - which, judging from the package files I have read, I think is against accepted good practice in Latex, but is clearly not rare. –  Charles Stewart Apr 19 '11 at 11:18
    
@Charles: I agree. Good packages have an internal definition which is used internally and the official user macro is \let to it. –  Martin Scharrer Apr 19 '11 at 11:28

You can load the soul package and then use \renewcommand to define your own macros.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.