List of newcommands usedCreate 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 fileIs there a good way to automatically generate a list of commands/environments defined in the preamble?Write 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

using `is` operator with value type tuples gives error

Is there any good reason to write "it is easy to see"?

How can a layman easily get the consensus view of what academia *thinks* about a subject?

Frame adjustment for engine

How did Thanos not realise this had happened at the end of Endgame?

CPLD based Pierce oscillator

As programers say: Strive to be lazy

Why does the headset man not get on the tractor?

How can dragons propel their breath attacks to a long distance

Rounding a number extracted by jq to limit the decimal points

If current results hold, Man City would win PL title

Why doesn't Rocket Lab use a solid stage?

What is the limit on how high you can fly up?

Can I use my laptop, which says 100-240V, in the USA?

On what legal basis did the UK remove the 'European Union' from its passport?

Anatomically Correct Carnivorous Tree

Replace all items that are not belong to characters and numbers by ' '

German characters on US-International keyboard layout

Can someone explain homicide-related death rates?

How to cope with regret and shame about not fully utilizing opportunities during PhD?

What information do scammers need to withdraw money from an account?

Longest Text in Latin

What are the holes in files created with fallocate?

Replace bar charts in a figure with text for each Y variable



List of newcommands used


Create 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 fileIs there a good way to automatically generate a list of commands/environments defined in the preamble?Write 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













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












  • @JohnKormylo Useful tip. Thanks.

    – Denis
    May 3 at 6: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












  • @JohnKormylo Useful tip. Thanks.

    – Denis
    May 3 at 6:33














4












4








4


1






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










asked May 2 at 14:14









DenisDenis

2,797620




2,797620












  • 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












  • @JohnKormylo Useful tip. Thanks.

    – Denis
    May 3 at 6: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












  • @JohnKormylo Useful tip. Thanks.

    – Denis
    May 3 at 6: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














@JohnKormylo Useful tip. Thanks.

– Denis
May 3 at 6:33






@JohnKormylo Useful tip. Thanks.

– Denis
May 3 at 6:33











2 Answers
2






active

oldest

votes


















10














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.

    – marmot
    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











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/3.0/"u003ecc by-sa 3.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

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









10














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.

    – marmot
    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














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.

    – marmot
    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












10








10







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








edited May 3 at 8:41

























answered May 2 at 15:24









schtandardschtandard

2,5871121




2,5871121












  • 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.

    – marmot
    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.

    – marmot
    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.

– marmot
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.

– marmot
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








edited May 3 at 22:19

























answered May 3 at 21:49









Matthias Borck-ElsnerMatthias Borck-Elsner

113




113












  • 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

















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

How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

What if the end-user didn't have the required library?What is setup.py?What is a clean, pythonic way to have multiple constructors in Python?What does Ruby have that Python doesn't, and vice versa?What is the reason for having '//' in Python?How do I create a namespace package in Python?How to package shared objects that python modules depend on?setuptools vs. distutils: why is distutils still a thing?Navigation in Windows 10 vs code not going to virtualenv library when the same library is installed at user levelPython create package for local usePackaging a project that uses multiple python versionsWhy is permission denied on pip install except for when “--user” is included at end of command?

Esgonzo ibérico Índice Descrición Distribución Hábitat Ameazas Notas Véxase tamén "Acerca dos nomes dos anfibios e réptiles galegos""Chalcides bedriagai"Chalcides bedriagai en Carrascal, L. M. Salvador, A. (Eds). Enciclopedia virtual de los vertebrados españoles. Museo Nacional de Ciencias Naturales, Madrid. España.Fotos