0

I've got a problem with my custom definitions-file. The file has hundreds of command definitions (with \newcommand or \renewcommand; mainly shortcuts for mathematical terms, programm names,...). I used the commands in this file to write a document. But now I saw, that im not allowed to submit such additional files, so all command-definitions have to be placed in the main-file. I don't want to search for all used commands by hand and I also don't want to paste the whole definitions-file into the main-file, because I only use a small subset.

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.

Thanks in advance! Greetings,

Freddy

  • 2
    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
  • 2
    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
3

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
\let\oldnewcommand\newcommand
\let\oldrenewcommand\renewcommand
\gdef\usedcommands{\par\bigskip\noindent Used commands:\par}
\def\newcommand#1{%
        \@namedef{\string#1}{\string #1}%
            \def#1{%
                \g@addto@macro\usedcommands{\ttfamily\@nameuse{\string#1}\par}%
                \def#1{}%
            }%
        \providecommand\@unuseful
}
\let\renewcommand\newcommand

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

% Some other adjustments:
\let\newcommand\oldnewcommand
\let\renewcommand\oldrenewcommand
\AtEndDocument{\usedcommands}
\makeatother
% ***************************

\begin{document}

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

\end{document}

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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