# clean up definition file


So my question is: Is there any way to get a list of the commands in my definitions-file that I use in the main-file? Or is there a way to automaticly delete all unused commands in the definitions-file?

I don't now if it is important in that case, but I compile the document with latex-dvips-ps2pdf.

Freddy

• I really don't think that the core of this question is opinion-based. The title may look like it, but the main question leaves little room for opinion (at least naively: an unused command is a command that is never called; of course there might be technical difficulties here, but I believe that is besides the point). – moewe Jan 11 at 11:16
• @moewe I don't understand your comment.. What do you mean with "opinion-based question"? – Freddy Jan 11 at 11:24
• The question was flagged as opinion-based (link to the review queue). (See tex.meta.stackexchange.com/q/4309/35864 and tex.stackexchange.com/help/dont-ask for a short explanation what opinion-based questions are and why they are usually considered a bad fit on this site.) I wanted to express my opinion that it is not in fact opinion based and should therefore not be closed as such. – moewe Jan 11 at 11:29
• Thank you for this clarification. I really don't see why anyone would flag my question as opinion-based... I have a problem with latex and I ask if there is a solution to it at all, I don't even ask for the best solution from several possible ones. What is wrong with that? If I had the same problem with a bibtex-file (several hundred entries and I want a new file with the used entries), I would know easy answers with a terminal-command and with the help of programms like jabref. But for this definition file I don't know an easy answer, so I asked for help... – Freddy Jan 11 at 12:09
• When confronting with a big preamble, I usually comment out everything, except for “everyday use” packages such as amsmath, geometry and some others. Then I run LaTeX and see what's missing from the error messages. It takes some time, but is guaranteed to slim the preamble to the bare minimum needed. – egreg Jan 11 at 12:54

If you really want something automatic, I've found this (very fragile and temporary) solution: you have to add some lines to your file of definitions and then you have to compile your document. All the commands defined in your definition file will "do nothing" in your document, but a list of the ones that have been used throughout the document will appear at the end of it.

Here you can see how it works:

\documentclass{article}

%\input{file.def}
% Content of definition file:
% ***************************
% Let's redefine \newcommand
\makeatletter
\gdef\usedcommands{\par\bigskip\noindent Used commands:\par}
\def\newcommand#1{%
\@namedef{\string#1}{\string #1}%
\def#1{%
\def#1{}%
}%
\providecommand\@unuseful
}

% Now the definitions you had before:
\newcommand\lorem{...}
\newcommand\ipsum[1]{#1 ...}
\newcommand\dolor{...}
\newcommand{\sit}{...}
\newcommand\amet{....}

\AtEndDocument{\usedcommands}
\makeatother
% ***************************

\begin{document}

Random text, \lorem\lorem\sit\ipsum
\ipsum
\sit

\end{document}


(I assumed you've never use \newcommand*, otherwise there would be some other work to do...)