List of newcommands usedHow are pgf-keys stored and is it possible to print a list of themCreate commands each of the text aligned horizontally?Warnings ignored if written in a custom auxiliary file (but not if written in .aux file)Automatically clean (numerous) customization macros gathered in an auxiliary fileWrite dynamic command name to an auxiliary fileDetect duplicates csnames defined via csdefwriting newcommands, user interface advice requestDefine a command printing later given textsStore values, text, commands in variablesclean up definition file

How to say dandruff in Esperanto?

How can I learn to write better questions to test for conceptual understanding?

voltage regulator current draw

I am often given, occasionally stolen, rarely sold, and never borrowed

Text on old-fashioned differential geometry

Why did Crew Dragon switch to burst disks instead of multiple check valves?

Can Boris Johnson invoke the Civil Contingencies Act to suspend the Benn law?

Is the algebra of compact operators flat?

In the comics, have any of the Robins called their costume "target attraction" for villains?

Who is Sifter, and what is "the so-called Sifter flare"?

String Format object extension

Incorrect mmap behavior when assembly files included in the project

When did 5 foot squares become standard in D&D?

How to protect my Wi-Fi password from being displayed by Android phones when sharing it with QR code?

Rule of thumb: how far before changing my chain to prevent cassette wear

Neither Raman nor IR Active vibrational modes

Advisor asked my whole slide presentation so she could give the presentation at international conference

Content Search Solr - Issue with the Like operator on my custom field

Anatomically Correct Baku

Are Snap and Flatpack apps safe to install? Are they "official", approved or tested for a particular distro version?

The travel to a friend

Translate "Everything burns" into classical Latin

Applicable country for US Visa In Icelandair Airline Website

Will Brexit potentially have an impact on intra-Schengen flights by EasyJet in November?



List of newcommands used


How are pgf-keys stored and is it possible to print a list of themCreate commands each of the text aligned horizontally?Warnings ignored if written in a custom auxiliary file (but not if written in .aux file)Automatically clean (numerous) customization macros gathered in an auxiliary fileWrite dynamic command name to an auxiliary fileDetect duplicates csnames defined via csdefwriting newcommands, user interface advice requestDefine a command printing later given textsStore values, text, commands in variablesclean up definition file






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









4

















I have large files that I am inputing the beginning of my texts that contain
all my newcommands. They are quite a few. Most of them will not be used in a given document. But which ones are used ?



Is it possible to write something to an auxiliary file saying if the newcommand that was defined was used or not in the text.



Although not very useful, I am including a MWE



documentclass[12pt]article
newcommandtitiHemixos castanonotus
newcommandeagHaliaeetus leucocephalus
begindocument
I my travels, I have seen many birds of type titi.
enddocument


An auxiliary file should then list the commands that were defined



Defined commands

titi
eag

Used commands

titi

Unused commands

eag


I am aware that packages define many newcommands. But I would be interested by user-defined newcommands only.










share|improve this question


























  • just delete all your definitions, and add the ones back if you get an undefined command error.

    – David Carlisle
    May 2 at 15:32











  • @DavidCarlisle OK. Will work for sure. Painful though. I was expecting a magic tracking macro.

    – Denis
    May 2 at 15:34






  • 1





    TeXnicCenter's Find in Files option can be used to list every occurrence of a macro name in a separate window frame.

    – John Kormylo
    May 2 at 16:33


















4

















I have large files that I am inputing the beginning of my texts that contain
all my newcommands. They are quite a few. Most of them will not be used in a given document. But which ones are used ?



Is it possible to write something to an auxiliary file saying if the newcommand that was defined was used or not in the text.



Although not very useful, I am including a MWE



documentclass[12pt]article
newcommandtitiHemixos castanonotus
newcommandeagHaliaeetus leucocephalus
begindocument
I my travels, I have seen many birds of type titi.
enddocument


An auxiliary file should then list the commands that were defined



Defined commands

titi
eag

Used commands

titi

Unused commands

eag


I am aware that packages define many newcommands. But I would be interested by user-defined newcommands only.










share|improve this question


























  • just delete all your definitions, and add the ones back if you get an undefined command error.

    – David Carlisle
    May 2 at 15:32











  • @DavidCarlisle OK. Will work for sure. Painful though. I was expecting a magic tracking macro.

    – Denis
    May 2 at 15:34






  • 1





    TeXnicCenter's Find in Files option can be used to list every occurrence of a macro name in a separate window frame.

    – John Kormylo
    May 2 at 16:33














4












4








4


0






I have large files that I am inputing the beginning of my texts that contain
all my newcommands. They are quite a few. Most of them will not be used in a given document. But which ones are used ?



Is it possible to write something to an auxiliary file saying if the newcommand that was defined was used or not in the text.



Although not very useful, I am including a MWE



documentclass[12pt]article
newcommandtitiHemixos castanonotus
newcommandeagHaliaeetus leucocephalus
begindocument
I my travels, I have seen many birds of type titi.
enddocument


An auxiliary file should then list the commands that were defined



Defined commands

titi
eag

Used commands

titi

Unused commands

eag


I am aware that packages define many newcommands. But I would be interested by user-defined newcommands only.










share|improve this question














I have large files that I am inputing the beginning of my texts that contain
all my newcommands. They are quite a few. Most of them will not be used in a given document. But which ones are used ?



Is it possible to write something to an auxiliary file saying if the newcommand that was defined was used or not in the text.



Although not very useful, I am including a MWE



documentclass[12pt]article
newcommandtitiHemixos castanonotus
newcommandeagHaliaeetus leucocephalus
begindocument
I my travels, I have seen many birds of type titi.
enddocument


An auxiliary file should then list the commands that were defined



Defined commands

titi
eag

Used commands

titi

Unused commands

eag


I am aware that packages define many newcommands. But I would be interested by user-defined newcommands only.







macros auxiliary-files






share|improve this question













share|improve this question











share|improve this question




share|improve this question



share|improve this question










asked May 2 at 14:14









DenisDenis

3,1166 silver badges25 bronze badges




3,1166 silver badges25 bronze badges















  • just delete all your definitions, and add the ones back if you get an undefined command error.

    – David Carlisle
    May 2 at 15:32











  • @DavidCarlisle OK. Will work for sure. Painful though. I was expecting a magic tracking macro.

    – Denis
    May 2 at 15:34






  • 1





    TeXnicCenter's Find in Files option can be used to list every occurrence of a macro name in a separate window frame.

    – John Kormylo
    May 2 at 16:33


















  • just delete all your definitions, and add the ones back if you get an undefined command error.

    – David Carlisle
    May 2 at 15:32











  • @DavidCarlisle OK. Will work for sure. Painful though. I was expecting a magic tracking macro.

    – Denis
    May 2 at 15:34






  • 1





    TeXnicCenter's Find in Files option can be used to list every occurrence of a macro name in a separate window frame.

    – John Kormylo
    May 2 at 16:33

















just delete all your definitions, and add the ones back if you get an undefined command error.

– David Carlisle
May 2 at 15:32





just delete all your definitions, and add the ones back if you get an undefined command error.

– David Carlisle
May 2 at 15:32













@DavidCarlisle OK. Will work for sure. Painful though. I was expecting a magic tracking macro.

– Denis
May 2 at 15:34





@DavidCarlisle OK. Will work for sure. Painful though. I was expecting a magic tracking macro.

– Denis
May 2 at 15:34




1




1





TeXnicCenter's Find in Files option can be used to list every occurrence of a macro name in a separate window frame.

– John Kormylo
May 2 at 16:33






TeXnicCenter's Find in Files option can be used to list every occurrence of a macro name in a separate window frame.

– John Kormylo
May 2 at 16:33











3 Answers
3






active

oldest

votes


















10







+500











documentclass[12pt]article

usepackageetoolbox

makeatletter
% This macro will contain all the tracked commands:
def@mycommands
% These macros enable and disable tracking the commands:
defstarttrackingnewcommands%
letold@@newcommand@newcommand
def@newcommand##1%
expandafterdefexpandafter@mycommandsexpandafter@mycommandsoneof@mycommands##1%
old@@newcommand##1%
%

defstoptrackingnewcommands%
let@newcommandold@@newcommand

% These macros are used to write to the log file:
defmycommand@used#1typeoutMy command `string #1' was used.
defmycommand@unused#1%
GenericWarning(mycommands)LaTeX Warning:
My command `string #1' was not used!%
%

% These macros mark a command as used or unused:
defmycommand@markunused#1%
expandaftergdefcsname mycommand@status@expandafter@gobblestring #1endcsnamemycommand@unused #1%
pretocmd #1mycommand@markused #1GenericWarning(mycommands)Could not patch `string #1' as unused!%
aftergroupmycommand@markunusedaftergroup #1%

defmycommand@markused#1%
expandaftergdefcsname mycommand@status@expandafter@gobblestring #1endcsnamemycommand@used #1%
patchcmd #1mycommand@markused #1GenericWarning(mycommands)Could not patch `string #1' as used!%
aftergroupmycommand@markusedaftergroup #1%

% This macro calls the appropriate logging macro for a command:
defmycommand@evaluateuse#1%
csname mycommand@status@expandafter@gobblestring#1endcsname

% Mark all commands as unused at begindocument:
AtBeginDocument%
letoneof@mycommandsmycommand@markunused
@mycommands

% Evaluate the use of the commands at enddocument:
AtEndDocument%
letoneof@mycommandsmycommand@evaluateuse
letmycommand@unused@gobble% first, only the used commands
@mycommands
letmycommand@used@gobble% then, only the unused commands
@mycommands
%

makeatother

starttrackingnewcommands
newcommandfoofoo
newcommandbazbar
newcommandtitiHemixos castanonotus
newcommandeagHaliaeetus leucocephalus
stoptrackingnewcommands

begindocument

I my travels, I have seen many birds of type titi.

enddocument


Towards the end of the log file you will find



My command `titi' was used.

LaTeX Warning: My command `foo' was not used! on input line 68.


LaTeX Warning: My command `baz' was not used! on input line 68.


LaTeX Warning: My command `eag' was not used! on input line 68.



Some Notes



This will break something if the first usage of one of your commands is used in a context like this:



defsomethingwithargument#1expansion
expandaftersomethingwithargumentoneofyourcommands


That is, if some command (somethingwithargument) consumes the start of the expansion of one of your commands, the fact that you inserted something at the start of that command to keep track of its usage will break this code. I do not know of any safer way to do this, though.




I chose to format the message for unused commands as a warning and the message for a used command as just that. You can of course choose to do this differently (or even write to an entirely different file if you prefer this).




Since this is a rather invasive process (modifying all your commands temporarily), there may well be side effects i cannot think of right now. If you spot any, feel free to add them here.



In any case, you should not use this as a permanent addition to your preamble, only as a technique to get a quick overview over which commands you use.






share|improve this answer




























  • Thanks indeed. Works fine here. Will wait a bit before I accept to see if anything new happens. Thanks for the detailed warnings: useful!!

    – Denis
    May 2 at 15:37







  • 1





    This is a really nice answer and I was not aware that this is possible. Do you think you could add an analogous recorder to tikzset such that one can keep track of which pgf keys have been set? This might be useful for those who want to safely nest tikzpictures.

    – user121799
    May 3 at 3:15






  • 1





    @Denis: I just noticed that commands were not marked as used when used inside of groups. I added a fix you in the definitions of the marking macros.

    – schtandard
    May 3 at 8:43











  • @marmot: It should be possible, I think. What would be the requirements for such a tracking macro? What information should be tracked and how would you want to be able to retrieve it?

    – schtandard
    May 3 at 8:45











  • @schtandard Thanks. I have tested the new version. Works fine.

    – Denis
    May 3 at 9:41


















1


















Here is a way to display used commands, for unused commands I did not find a solution. Search and replace your commands adding a display
i.e replace titi with displaytiti



 documentclass[12pt]article
newcountcommandnum
commandnum=0
newwritedisplayed
immediateopenoutdisplayed=jobname.dis
defdisplayedcommands#1vfill section#1 vskipbaselineskip immediatecloseoutdisplayed inputjobname.dis
defdisplay#1advancecommandnum by 1 #1textsuperscript(thecommandnum) immediatewritedisplayednoindent #1 P.thepage called by (thecommandnum) noexpandstringnoexpand#1'' vskip0.2baselineskip
newcommandtiti``Hemixos castanonotus''
newcommandeag``Haliaeetus leucocephalus''
begindocument
sectionTest
In my travels, I have seen many birds of type displaytiti
In my travels, I have seen many birds of type displayeag

In my travels, I have seen many birds of type displayeag
displayedcommandsUsed Commands
enddocument





share|improve this answer




























  • It is very much better to add a comment in the newcommands instead of tracking them afterwards.

    – Matthias Borck-Elsner
    May 4 at 2:53


















1


















Another Option that occurs to me off the top of my head, depending on the diagnostic purposes of your question... it may be of interest to know not just which commands were used or not, but rather how often they were used. To this end, consider following:



documentclass[12pt]article
usepackageetoolbox
newcommanddisplayTracked
makeatletter

newcommandtrackedCommand[2]% This will define a tracked command.
% Define the command as it was original intended.
expandafternewcommandcsname#1endcsname#2 refstepcounter#1Count

% Define a counter to track that specific command.
newcounter#1Count
setcounter#1Count0% Initialize it to zero as the command hasn't been used yet.

% Update the display command to include the new command counter.
csapptodisplayTrackedThe command #1 has been used arabic#1Count times \


makeatother
trackedCommandtitiHemixos castanonotus
trackedCommandeagHaliaeetus leucocephalus
trackedCommandanothercommandThis command won't be used at all, but still tracked.
begindocument
I my travels, I have seen many birds of type titi. What about titi or eag or just titi ?

displayTracked
enddocument


enter image description here



Someone better at LaTeX than I might be able to get the command trackedCommand to take in a csname rather than the text name (ie allow you to define a command identically to the newcommand syntax using titi rather than titi), but I couldn't get a nice solution working in the time frame I was willing to work on this. It's worth a note that the trackedCommand command will take in nonstandard command names (eg those with spaces, or arabic numerals); moreover you can decide if you want to track each command individually, rather than always tracking every command (in case there are commands you already know are heavily used or rarely used, and don't need to display the stats).



Moreover the displayTracked is what gives you the output, so simply commenting out (or not including) that command will allow you to only get tracking info when desired. You could also use the command and pipe it out to an aux file or latex warning or whatever else you might want it for.






share|improve this answer



























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "85"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f488785%2flist-of-newcommands-used%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown


























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    10







    +500











    documentclass[12pt]article

    usepackageetoolbox

    makeatletter
    % This macro will contain all the tracked commands:
    def@mycommands
    % These macros enable and disable tracking the commands:
    defstarttrackingnewcommands%
    letold@@newcommand@newcommand
    def@newcommand##1%
    expandafterdefexpandafter@mycommandsexpandafter@mycommandsoneof@mycommands##1%
    old@@newcommand##1%
    %

    defstoptrackingnewcommands%
    let@newcommandold@@newcommand

    % These macros are used to write to the log file:
    defmycommand@used#1typeoutMy command `string #1' was used.
    defmycommand@unused#1%
    GenericWarning(mycommands)LaTeX Warning:
    My command `string #1' was not used!%
    %

    % These macros mark a command as used or unused:
    defmycommand@markunused#1%
    expandaftergdefcsname mycommand@status@expandafter@gobblestring #1endcsnamemycommand@unused #1%
    pretocmd #1mycommand@markused #1GenericWarning(mycommands)Could not patch `string #1' as unused!%
    aftergroupmycommand@markunusedaftergroup #1%

    defmycommand@markused#1%
    expandaftergdefcsname mycommand@status@expandafter@gobblestring #1endcsnamemycommand@used #1%
    patchcmd #1mycommand@markused #1GenericWarning(mycommands)Could not patch `string #1' as used!%
    aftergroupmycommand@markusedaftergroup #1%

    % This macro calls the appropriate logging macro for a command:
    defmycommand@evaluateuse#1%
    csname mycommand@status@expandafter@gobblestring#1endcsname

    % Mark all commands as unused at begindocument:
    AtBeginDocument%
    letoneof@mycommandsmycommand@markunused
    @mycommands

    % Evaluate the use of the commands at enddocument:
    AtEndDocument%
    letoneof@mycommandsmycommand@evaluateuse
    letmycommand@unused@gobble% first, only the used commands
    @mycommands
    letmycommand@used@gobble% then, only the unused commands
    @mycommands
    %

    makeatother

    starttrackingnewcommands
    newcommandfoofoo
    newcommandbazbar
    newcommandtitiHemixos castanonotus
    newcommandeagHaliaeetus leucocephalus
    stoptrackingnewcommands

    begindocument

    I my travels, I have seen many birds of type titi.

    enddocument


    Towards the end of the log file you will find



    My command `titi' was used.

    LaTeX Warning: My command `foo' was not used! on input line 68.


    LaTeX Warning: My command `baz' was not used! on input line 68.


    LaTeX Warning: My command `eag' was not used! on input line 68.



    Some Notes



    This will break something if the first usage of one of your commands is used in a context like this:



    defsomethingwithargument#1expansion
    expandaftersomethingwithargumentoneofyourcommands


    That is, if some command (somethingwithargument) consumes the start of the expansion of one of your commands, the fact that you inserted something at the start of that command to keep track of its usage will break this code. I do not know of any safer way to do this, though.




    I chose to format the message for unused commands as a warning and the message for a used command as just that. You can of course choose to do this differently (or even write to an entirely different file if you prefer this).




    Since this is a rather invasive process (modifying all your commands temporarily), there may well be side effects i cannot think of right now. If you spot any, feel free to add them here.



    In any case, you should not use this as a permanent addition to your preamble, only as a technique to get a quick overview over which commands you use.






    share|improve this answer




























    • Thanks indeed. Works fine here. Will wait a bit before I accept to see if anything new happens. Thanks for the detailed warnings: useful!!

      – Denis
      May 2 at 15:37







    • 1





      This is a really nice answer and I was not aware that this is possible. Do you think you could add an analogous recorder to tikzset such that one can keep track of which pgf keys have been set? This might be useful for those who want to safely nest tikzpictures.

      – user121799
      May 3 at 3:15






    • 1





      @Denis: I just noticed that commands were not marked as used when used inside of groups. I added a fix you in the definitions of the marking macros.

      – schtandard
      May 3 at 8:43











    • @marmot: It should be possible, I think. What would be the requirements for such a tracking macro? What information should be tracked and how would you want to be able to retrieve it?

      – schtandard
      May 3 at 8:45











    • @schtandard Thanks. I have tested the new version. Works fine.

      – Denis
      May 3 at 9:41















    10







    +500











    documentclass[12pt]article

    usepackageetoolbox

    makeatletter
    % This macro will contain all the tracked commands:
    def@mycommands
    % These macros enable and disable tracking the commands:
    defstarttrackingnewcommands%
    letold@@newcommand@newcommand
    def@newcommand##1%
    expandafterdefexpandafter@mycommandsexpandafter@mycommandsoneof@mycommands##1%
    old@@newcommand##1%
    %

    defstoptrackingnewcommands%
    let@newcommandold@@newcommand

    % These macros are used to write to the log file:
    defmycommand@used#1typeoutMy command `string #1' was used.
    defmycommand@unused#1%
    GenericWarning(mycommands)LaTeX Warning:
    My command `string #1' was not used!%
    %

    % These macros mark a command as used or unused:
    defmycommand@markunused#1%
    expandaftergdefcsname mycommand@status@expandafter@gobblestring #1endcsnamemycommand@unused #1%
    pretocmd #1mycommand@markused #1GenericWarning(mycommands)Could not patch `string #1' as unused!%
    aftergroupmycommand@markunusedaftergroup #1%

    defmycommand@markused#1%
    expandaftergdefcsname mycommand@status@expandafter@gobblestring #1endcsnamemycommand@used #1%
    patchcmd #1mycommand@markused #1GenericWarning(mycommands)Could not patch `string #1' as used!%
    aftergroupmycommand@markusedaftergroup #1%

    % This macro calls the appropriate logging macro for a command:
    defmycommand@evaluateuse#1%
    csname mycommand@status@expandafter@gobblestring#1endcsname

    % Mark all commands as unused at begindocument:
    AtBeginDocument%
    letoneof@mycommandsmycommand@markunused
    @mycommands

    % Evaluate the use of the commands at enddocument:
    AtEndDocument%
    letoneof@mycommandsmycommand@evaluateuse
    letmycommand@unused@gobble% first, only the used commands
    @mycommands
    letmycommand@used@gobble% then, only the unused commands
    @mycommands
    %

    makeatother

    starttrackingnewcommands
    newcommandfoofoo
    newcommandbazbar
    newcommandtitiHemixos castanonotus
    newcommandeagHaliaeetus leucocephalus
    stoptrackingnewcommands

    begindocument

    I my travels, I have seen many birds of type titi.

    enddocument


    Towards the end of the log file you will find



    My command `titi' was used.

    LaTeX Warning: My command `foo' was not used! on input line 68.


    LaTeX Warning: My command `baz' was not used! on input line 68.


    LaTeX Warning: My command `eag' was not used! on input line 68.



    Some Notes



    This will break something if the first usage of one of your commands is used in a context like this:



    defsomethingwithargument#1expansion
    expandaftersomethingwithargumentoneofyourcommands


    That is, if some command (somethingwithargument) consumes the start of the expansion of one of your commands, the fact that you inserted something at the start of that command to keep track of its usage will break this code. I do not know of any safer way to do this, though.




    I chose to format the message for unused commands as a warning and the message for a used command as just that. You can of course choose to do this differently (or even write to an entirely different file if you prefer this).




    Since this is a rather invasive process (modifying all your commands temporarily), there may well be side effects i cannot think of right now. If you spot any, feel free to add them here.



    In any case, you should not use this as a permanent addition to your preamble, only as a technique to get a quick overview over which commands you use.






    share|improve this answer




























    • Thanks indeed. Works fine here. Will wait a bit before I accept to see if anything new happens. Thanks for the detailed warnings: useful!!

      – Denis
      May 2 at 15:37







    • 1





      This is a really nice answer and I was not aware that this is possible. Do you think you could add an analogous recorder to tikzset such that one can keep track of which pgf keys have been set? This might be useful for those who want to safely nest tikzpictures.

      – user121799
      May 3 at 3:15






    • 1





      @Denis: I just noticed that commands were not marked as used when used inside of groups. I added a fix you in the definitions of the marking macros.

      – schtandard
      May 3 at 8:43











    • @marmot: It should be possible, I think. What would be the requirements for such a tracking macro? What information should be tracked and how would you want to be able to retrieve it?

      – schtandard
      May 3 at 8:45











    • @schtandard Thanks. I have tested the new version. Works fine.

      – Denis
      May 3 at 9:41













    10







    +500







    10







    +500



    10






    +500





    documentclass[12pt]article

    usepackageetoolbox

    makeatletter
    % This macro will contain all the tracked commands:
    def@mycommands
    % These macros enable and disable tracking the commands:
    defstarttrackingnewcommands%
    letold@@newcommand@newcommand
    def@newcommand##1%
    expandafterdefexpandafter@mycommandsexpandafter@mycommandsoneof@mycommands##1%
    old@@newcommand##1%
    %

    defstoptrackingnewcommands%
    let@newcommandold@@newcommand

    % These macros are used to write to the log file:
    defmycommand@used#1typeoutMy command `string #1' was used.
    defmycommand@unused#1%
    GenericWarning(mycommands)LaTeX Warning:
    My command `string #1' was not used!%
    %

    % These macros mark a command as used or unused:
    defmycommand@markunused#1%
    expandaftergdefcsname mycommand@status@expandafter@gobblestring #1endcsnamemycommand@unused #1%
    pretocmd #1mycommand@markused #1GenericWarning(mycommands)Could not patch `string #1' as unused!%
    aftergroupmycommand@markunusedaftergroup #1%

    defmycommand@markused#1%
    expandaftergdefcsname mycommand@status@expandafter@gobblestring #1endcsnamemycommand@used #1%
    patchcmd #1mycommand@markused #1GenericWarning(mycommands)Could not patch `string #1' as used!%
    aftergroupmycommand@markusedaftergroup #1%

    % This macro calls the appropriate logging macro for a command:
    defmycommand@evaluateuse#1%
    csname mycommand@status@expandafter@gobblestring#1endcsname

    % Mark all commands as unused at begindocument:
    AtBeginDocument%
    letoneof@mycommandsmycommand@markunused
    @mycommands

    % Evaluate the use of the commands at enddocument:
    AtEndDocument%
    letoneof@mycommandsmycommand@evaluateuse
    letmycommand@unused@gobble% first, only the used commands
    @mycommands
    letmycommand@used@gobble% then, only the unused commands
    @mycommands
    %

    makeatother

    starttrackingnewcommands
    newcommandfoofoo
    newcommandbazbar
    newcommandtitiHemixos castanonotus
    newcommandeagHaliaeetus leucocephalus
    stoptrackingnewcommands

    begindocument

    I my travels, I have seen many birds of type titi.

    enddocument


    Towards the end of the log file you will find



    My command `titi' was used.

    LaTeX Warning: My command `foo' was not used! on input line 68.


    LaTeX Warning: My command `baz' was not used! on input line 68.


    LaTeX Warning: My command `eag' was not used! on input line 68.



    Some Notes



    This will break something if the first usage of one of your commands is used in a context like this:



    defsomethingwithargument#1expansion
    expandaftersomethingwithargumentoneofyourcommands


    That is, if some command (somethingwithargument) consumes the start of the expansion of one of your commands, the fact that you inserted something at the start of that command to keep track of its usage will break this code. I do not know of any safer way to do this, though.




    I chose to format the message for unused commands as a warning and the message for a used command as just that. You can of course choose to do this differently (or even write to an entirely different file if you prefer this).




    Since this is a rather invasive process (modifying all your commands temporarily), there may well be side effects i cannot think of right now. If you spot any, feel free to add them here.



    In any case, you should not use this as a permanent addition to your preamble, only as a technique to get a quick overview over which commands you use.






    share|improve this answer
















    documentclass[12pt]article

    usepackageetoolbox

    makeatletter
    % This macro will contain all the tracked commands:
    def@mycommands
    % These macros enable and disable tracking the commands:
    defstarttrackingnewcommands%
    letold@@newcommand@newcommand
    def@newcommand##1%
    expandafterdefexpandafter@mycommandsexpandafter@mycommandsoneof@mycommands##1%
    old@@newcommand##1%
    %

    defstoptrackingnewcommands%
    let@newcommandold@@newcommand

    % These macros are used to write to the log file:
    defmycommand@used#1typeoutMy command `string #1' was used.
    defmycommand@unused#1%
    GenericWarning(mycommands)LaTeX Warning:
    My command `string #1' was not used!%
    %

    % These macros mark a command as used or unused:
    defmycommand@markunused#1%
    expandaftergdefcsname mycommand@status@expandafter@gobblestring #1endcsnamemycommand@unused #1%
    pretocmd #1mycommand@markused #1GenericWarning(mycommands)Could not patch `string #1' as unused!%
    aftergroupmycommand@markunusedaftergroup #1%

    defmycommand@markused#1%
    expandaftergdefcsname mycommand@status@expandafter@gobblestring #1endcsnamemycommand@used #1%
    patchcmd #1mycommand@markused #1GenericWarning(mycommands)Could not patch `string #1' as used!%
    aftergroupmycommand@markusedaftergroup #1%

    % This macro calls the appropriate logging macro for a command:
    defmycommand@evaluateuse#1%
    csname mycommand@status@expandafter@gobblestring#1endcsname

    % Mark all commands as unused at begindocument:
    AtBeginDocument%
    letoneof@mycommandsmycommand@markunused
    @mycommands

    % Evaluate the use of the commands at enddocument:
    AtEndDocument%
    letoneof@mycommandsmycommand@evaluateuse
    letmycommand@unused@gobble% first, only the used commands
    @mycommands
    letmycommand@used@gobble% then, only the unused commands
    @mycommands
    %

    makeatother

    starttrackingnewcommands
    newcommandfoofoo
    newcommandbazbar
    newcommandtitiHemixos castanonotus
    newcommandeagHaliaeetus leucocephalus
    stoptrackingnewcommands

    begindocument

    I my travels, I have seen many birds of type titi.

    enddocument


    Towards the end of the log file you will find



    My command `titi' was used.

    LaTeX Warning: My command `foo' was not used! on input line 68.


    LaTeX Warning: My command `baz' was not used! on input line 68.


    LaTeX Warning: My command `eag' was not used! on input line 68.



    Some Notes



    This will break something if the first usage of one of your commands is used in a context like this:



    defsomethingwithargument#1expansion
    expandaftersomethingwithargumentoneofyourcommands


    That is, if some command (somethingwithargument) consumes the start of the expansion of one of your commands, the fact that you inserted something at the start of that command to keep track of its usage will break this code. I do not know of any safer way to do this, though.




    I chose to format the message for unused commands as a warning and the message for a used command as just that. You can of course choose to do this differently (or even write to an entirely different file if you prefer this).




    Since this is a rather invasive process (modifying all your commands temporarily), there may well be side effects i cannot think of right now. If you spot any, feel free to add them here.



    In any case, you should not use this as a permanent addition to your preamble, only as a technique to get a quick overview over which commands you use.







    share|improve this answer















    share|improve this answer




    share|improve this answer



    share|improve this answer








    edited May 3 at 8:41

























    answered May 2 at 15:24









    schtandardschtandard

    5,7941 gold badge14 silver badges32 bronze badges




    5,7941 gold badge14 silver badges32 bronze badges















    • Thanks indeed. Works fine here. Will wait a bit before I accept to see if anything new happens. Thanks for the detailed warnings: useful!!

      – Denis
      May 2 at 15:37







    • 1





      This is a really nice answer and I was not aware that this is possible. Do you think you could add an analogous recorder to tikzset such that one can keep track of which pgf keys have been set? This might be useful for those who want to safely nest tikzpictures.

      – user121799
      May 3 at 3:15






    • 1





      @Denis: I just noticed that commands were not marked as used when used inside of groups. I added a fix you in the definitions of the marking macros.

      – schtandard
      May 3 at 8:43











    • @marmot: It should be possible, I think. What would be the requirements for such a tracking macro? What information should be tracked and how would you want to be able to retrieve it?

      – schtandard
      May 3 at 8:45











    • @schtandard Thanks. I have tested the new version. Works fine.

      – Denis
      May 3 at 9:41

















    • Thanks indeed. Works fine here. Will wait a bit before I accept to see if anything new happens. Thanks for the detailed warnings: useful!!

      – Denis
      May 2 at 15:37







    • 1





      This is a really nice answer and I was not aware that this is possible. Do you think you could add an analogous recorder to tikzset such that one can keep track of which pgf keys have been set? This might be useful for those who want to safely nest tikzpictures.

      – user121799
      May 3 at 3:15






    • 1





      @Denis: I just noticed that commands were not marked as used when used inside of groups. I added a fix you in the definitions of the marking macros.

      – schtandard
      May 3 at 8:43











    • @marmot: It should be possible, I think. What would be the requirements for such a tracking macro? What information should be tracked and how would you want to be able to retrieve it?

      – schtandard
      May 3 at 8:45











    • @schtandard Thanks. I have tested the new version. Works fine.

      – Denis
      May 3 at 9:41
















    Thanks indeed. Works fine here. Will wait a bit before I accept to see if anything new happens. Thanks for the detailed warnings: useful!!

    – Denis
    May 2 at 15:37






    Thanks indeed. Works fine here. Will wait a bit before I accept to see if anything new happens. Thanks for the detailed warnings: useful!!

    – Denis
    May 2 at 15:37





    1




    1





    This is a really nice answer and I was not aware that this is possible. Do you think you could add an analogous recorder to tikzset such that one can keep track of which pgf keys have been set? This might be useful for those who want to safely nest tikzpictures.

    – user121799
    May 3 at 3:15





    This is a really nice answer and I was not aware that this is possible. Do you think you could add an analogous recorder to tikzset such that one can keep track of which pgf keys have been set? This might be useful for those who want to safely nest tikzpictures.

    – user121799
    May 3 at 3:15




    1




    1





    @Denis: I just noticed that commands were not marked as used when used inside of groups. I added a fix you in the definitions of the marking macros.

    – schtandard
    May 3 at 8:43





    @Denis: I just noticed that commands were not marked as used when used inside of groups. I added a fix you in the definitions of the marking macros.

    – schtandard
    May 3 at 8:43













    @marmot: It should be possible, I think. What would be the requirements for such a tracking macro? What information should be tracked and how would you want to be able to retrieve it?

    – schtandard
    May 3 at 8:45





    @marmot: It should be possible, I think. What would be the requirements for such a tracking macro? What information should be tracked and how would you want to be able to retrieve it?

    – schtandard
    May 3 at 8:45













    @schtandard Thanks. I have tested the new version. Works fine.

    – Denis
    May 3 at 9:41





    @schtandard Thanks. I have tested the new version. Works fine.

    – Denis
    May 3 at 9:41













    1


















    Here is a way to display used commands, for unused commands I did not find a solution. Search and replace your commands adding a display
    i.e replace titi with displaytiti



     documentclass[12pt]article
    newcountcommandnum
    commandnum=0
    newwritedisplayed
    immediateopenoutdisplayed=jobname.dis
    defdisplayedcommands#1vfill section#1 vskipbaselineskip immediatecloseoutdisplayed inputjobname.dis
    defdisplay#1advancecommandnum by 1 #1textsuperscript(thecommandnum) immediatewritedisplayednoindent #1 P.thepage called by (thecommandnum) noexpandstringnoexpand#1'' vskip0.2baselineskip
    newcommandtiti``Hemixos castanonotus''
    newcommandeag``Haliaeetus leucocephalus''
    begindocument
    sectionTest
    In my travels, I have seen many birds of type displaytiti
    In my travels, I have seen many birds of type displayeag

    In my travels, I have seen many birds of type displayeag
    displayedcommandsUsed Commands
    enddocument





    share|improve this answer




























    • It is very much better to add a comment in the newcommands instead of tracking them afterwards.

      – Matthias Borck-Elsner
      May 4 at 2:53















    1


















    Here is a way to display used commands, for unused commands I did not find a solution. Search and replace your commands adding a display
    i.e replace titi with displaytiti



     documentclass[12pt]article
    newcountcommandnum
    commandnum=0
    newwritedisplayed
    immediateopenoutdisplayed=jobname.dis
    defdisplayedcommands#1vfill section#1 vskipbaselineskip immediatecloseoutdisplayed inputjobname.dis
    defdisplay#1advancecommandnum by 1 #1textsuperscript(thecommandnum) immediatewritedisplayednoindent #1 P.thepage called by (thecommandnum) noexpandstringnoexpand#1'' vskip0.2baselineskip
    newcommandtiti``Hemixos castanonotus''
    newcommandeag``Haliaeetus leucocephalus''
    begindocument
    sectionTest
    In my travels, I have seen many birds of type displaytiti
    In my travels, I have seen many birds of type displayeag

    In my travels, I have seen many birds of type displayeag
    displayedcommandsUsed Commands
    enddocument





    share|improve this answer




























    • It is very much better to add a comment in the newcommands instead of tracking them afterwards.

      – Matthias Borck-Elsner
      May 4 at 2:53













    1














    1










    1









    Here is a way to display used commands, for unused commands I did not find a solution. Search and replace your commands adding a display
    i.e replace titi with displaytiti



     documentclass[12pt]article
    newcountcommandnum
    commandnum=0
    newwritedisplayed
    immediateopenoutdisplayed=jobname.dis
    defdisplayedcommands#1vfill section#1 vskipbaselineskip immediatecloseoutdisplayed inputjobname.dis
    defdisplay#1advancecommandnum by 1 #1textsuperscript(thecommandnum) immediatewritedisplayednoindent #1 P.thepage called by (thecommandnum) noexpandstringnoexpand#1'' vskip0.2baselineskip
    newcommandtiti``Hemixos castanonotus''
    newcommandeag``Haliaeetus leucocephalus''
    begindocument
    sectionTest
    In my travels, I have seen many birds of type displaytiti
    In my travels, I have seen many birds of type displayeag

    In my travels, I have seen many birds of type displayeag
    displayedcommandsUsed Commands
    enddocument





    share|improve this answer
















    Here is a way to display used commands, for unused commands I did not find a solution. Search and replace your commands adding a display
    i.e replace titi with displaytiti



     documentclass[12pt]article
    newcountcommandnum
    commandnum=0
    newwritedisplayed
    immediateopenoutdisplayed=jobname.dis
    defdisplayedcommands#1vfill section#1 vskipbaselineskip immediatecloseoutdisplayed inputjobname.dis
    defdisplay#1advancecommandnum by 1 #1textsuperscript(thecommandnum) immediatewritedisplayednoindent #1 P.thepage called by (thecommandnum) noexpandstringnoexpand#1'' vskip0.2baselineskip
    newcommandtiti``Hemixos castanonotus''
    newcommandeag``Haliaeetus leucocephalus''
    begindocument
    sectionTest
    In my travels, I have seen many birds of type displaytiti
    In my travels, I have seen many birds of type displayeag

    In my travels, I have seen many birds of type displayeag
    displayedcommandsUsed Commands
    enddocument






    share|improve this answer















    share|improve this answer




    share|improve this answer



    share|improve this answer








    edited May 3 at 22:19

























    answered May 3 at 21:49









    Matthias Borck-ElsnerMatthias Borck-Elsner

    164 bronze badges




    164 bronze badges















    • It is very much better to add a comment in the newcommands instead of tracking them afterwards.

      – Matthias Borck-Elsner
      May 4 at 2:53

















    • It is very much better to add a comment in the newcommands instead of tracking them afterwards.

      – Matthias Borck-Elsner
      May 4 at 2:53
















    It is very much better to add a comment in the newcommands instead of tracking them afterwards.

    – Matthias Borck-Elsner
    May 4 at 2:53





    It is very much better to add a comment in the newcommands instead of tracking them afterwards.

    – Matthias Borck-Elsner
    May 4 at 2:53











    1


















    Another Option that occurs to me off the top of my head, depending on the diagnostic purposes of your question... it may be of interest to know not just which commands were used or not, but rather how often they were used. To this end, consider following:



    documentclass[12pt]article
    usepackageetoolbox
    newcommanddisplayTracked
    makeatletter

    newcommandtrackedCommand[2]% This will define a tracked command.
    % Define the command as it was original intended.
    expandafternewcommandcsname#1endcsname#2 refstepcounter#1Count

    % Define a counter to track that specific command.
    newcounter#1Count
    setcounter#1Count0% Initialize it to zero as the command hasn't been used yet.

    % Update the display command to include the new command counter.
    csapptodisplayTrackedThe command #1 has been used arabic#1Count times \


    makeatother
    trackedCommandtitiHemixos castanonotus
    trackedCommandeagHaliaeetus leucocephalus
    trackedCommandanothercommandThis command won't be used at all, but still tracked.
    begindocument
    I my travels, I have seen many birds of type titi. What about titi or eag or just titi ?

    displayTracked
    enddocument


    enter image description here



    Someone better at LaTeX than I might be able to get the command trackedCommand to take in a csname rather than the text name (ie allow you to define a command identically to the newcommand syntax using titi rather than titi), but I couldn't get a nice solution working in the time frame I was willing to work on this. It's worth a note that the trackedCommand command will take in nonstandard command names (eg those with spaces, or arabic numerals); moreover you can decide if you want to track each command individually, rather than always tracking every command (in case there are commands you already know are heavily used or rarely used, and don't need to display the stats).



    Moreover the displayTracked is what gives you the output, so simply commenting out (or not including) that command will allow you to only get tracking info when desired. You could also use the command and pipe it out to an aux file or latex warning or whatever else you might want it for.






    share|improve this answer






























      1


















      Another Option that occurs to me off the top of my head, depending on the diagnostic purposes of your question... it may be of interest to know not just which commands were used or not, but rather how often they were used. To this end, consider following:



      documentclass[12pt]article
      usepackageetoolbox
      newcommanddisplayTracked
      makeatletter

      newcommandtrackedCommand[2]% This will define a tracked command.
      % Define the command as it was original intended.
      expandafternewcommandcsname#1endcsname#2 refstepcounter#1Count

      % Define a counter to track that specific command.
      newcounter#1Count
      setcounter#1Count0% Initialize it to zero as the command hasn't been used yet.

      % Update the display command to include the new command counter.
      csapptodisplayTrackedThe command #1 has been used arabic#1Count times \


      makeatother
      trackedCommandtitiHemixos castanonotus
      trackedCommandeagHaliaeetus leucocephalus
      trackedCommandanothercommandThis command won't be used at all, but still tracked.
      begindocument
      I my travels, I have seen many birds of type titi. What about titi or eag or just titi ?

      displayTracked
      enddocument


      enter image description here



      Someone better at LaTeX than I might be able to get the command trackedCommand to take in a csname rather than the text name (ie allow you to define a command identically to the newcommand syntax using titi rather than titi), but I couldn't get a nice solution working in the time frame I was willing to work on this. It's worth a note that the trackedCommand command will take in nonstandard command names (eg those with spaces, or arabic numerals); moreover you can decide if you want to track each command individually, rather than always tracking every command (in case there are commands you already know are heavily used or rarely used, and don't need to display the stats).



      Moreover the displayTracked is what gives you the output, so simply commenting out (or not including) that command will allow you to only get tracking info when desired. You could also use the command and pipe it out to an aux file or latex warning or whatever else you might want it for.






      share|improve this answer




























        1














        1










        1









        Another Option that occurs to me off the top of my head, depending on the diagnostic purposes of your question... it may be of interest to know not just which commands were used or not, but rather how often they were used. To this end, consider following:



        documentclass[12pt]article
        usepackageetoolbox
        newcommanddisplayTracked
        makeatletter

        newcommandtrackedCommand[2]% This will define a tracked command.
        % Define the command as it was original intended.
        expandafternewcommandcsname#1endcsname#2 refstepcounter#1Count

        % Define a counter to track that specific command.
        newcounter#1Count
        setcounter#1Count0% Initialize it to zero as the command hasn't been used yet.

        % Update the display command to include the new command counter.
        csapptodisplayTrackedThe command #1 has been used arabic#1Count times \


        makeatother
        trackedCommandtitiHemixos castanonotus
        trackedCommandeagHaliaeetus leucocephalus
        trackedCommandanothercommandThis command won't be used at all, but still tracked.
        begindocument
        I my travels, I have seen many birds of type titi. What about titi or eag or just titi ?

        displayTracked
        enddocument


        enter image description here



        Someone better at LaTeX than I might be able to get the command trackedCommand to take in a csname rather than the text name (ie allow you to define a command identically to the newcommand syntax using titi rather than titi), but I couldn't get a nice solution working in the time frame I was willing to work on this. It's worth a note that the trackedCommand command will take in nonstandard command names (eg those with spaces, or arabic numerals); moreover you can decide if you want to track each command individually, rather than always tracking every command (in case there are commands you already know are heavily used or rarely used, and don't need to display the stats).



        Moreover the displayTracked is what gives you the output, so simply commenting out (or not including) that command will allow you to only get tracking info when desired. You could also use the command and pipe it out to an aux file or latex warning or whatever else you might want it for.






        share|improve this answer














        Another Option that occurs to me off the top of my head, depending on the diagnostic purposes of your question... it may be of interest to know not just which commands were used or not, but rather how often they were used. To this end, consider following:



        documentclass[12pt]article
        usepackageetoolbox
        newcommanddisplayTracked
        makeatletter

        newcommandtrackedCommand[2]% This will define a tracked command.
        % Define the command as it was original intended.
        expandafternewcommandcsname#1endcsname#2 refstepcounter#1Count

        % Define a counter to track that specific command.
        newcounter#1Count
        setcounter#1Count0% Initialize it to zero as the command hasn't been used yet.

        % Update the display command to include the new command counter.
        csapptodisplayTrackedThe command #1 has been used arabic#1Count times \


        makeatother
        trackedCommandtitiHemixos castanonotus
        trackedCommandeagHaliaeetus leucocephalus
        trackedCommandanothercommandThis command won't be used at all, but still tracked.
        begindocument
        I my travels, I have seen many birds of type titi. What about titi or eag or just titi ?

        displayTracked
        enddocument


        enter image description here



        Someone better at LaTeX than I might be able to get the command trackedCommand to take in a csname rather than the text name (ie allow you to define a command identically to the newcommand syntax using titi rather than titi), but I couldn't get a nice solution working in the time frame I was willing to work on this. It's worth a note that the trackedCommand command will take in nonstandard command names (eg those with spaces, or arabic numerals); moreover you can decide if you want to track each command individually, rather than always tracking every command (in case there are commands you already know are heavily used or rarely used, and don't need to display the stats).



        Moreover the displayTracked is what gives you the output, so simply commenting out (or not including) that command will allow you to only get tracking info when desired. You could also use the command and pipe it out to an aux file or latex warning or whatever else you might want it for.







        share|improve this answer













        share|improve this answer




        share|improve this answer



        share|improve this answer










        answered Aug 4 at 21:23









        JasonJason

        4973 silver badges8 bronze badges




        4973 silver badges8 bronze badges































            draft saved

            draft discarded















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f488785%2flist-of-newcommands-used%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown









            Popular posts from this blog

            Tamil (spriik) Luke uk diar | Nawigatjuun

            Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

            Where does the image of a data connector as a sharp metal spike originate from?Where does the concept of infected people turning into zombies only after death originate from?Where does the motif of a reanimated human head originate?Where did the notion that Dragons could speak originate?Where does the archetypal image of the 'Grey' alien come from?Where did the suffix '-Man' originate?Where does the notion of being injured or killed by an illusion originate?Where did the term “sophont” originate?Where does the trope of magic spells being driven by advanced technology originate from?Where did the term “the living impaired” originate?