GeneralLocation of Macro Definition

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
wcw
Posts: 20
Joined: Thu Mar 08, 2012 12:35 pm

Location of Macro Definition

Post by wcw »

I am learning modifying the macro now. The problem is that I could not know the file where the definition of the macro is place. For example, I want to change the name for the graph, I could find the source online for help.
The code is:

Code: Select all

\renewcommand{\figurename}{Fig.}
With the code above, I could implement changing "Figure" into "Fig." But the problem is that I want to change more things, from where I can know the exact definition of \figurename or other macros? Is there any certaion type of file for defining these macros?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Location of Macro Definition

Post by localghost »

Macros are defined at different places. Those which are essential for every document are defined in the LaTeX kernel (files with suffix *.ltx). Macros like \figurename, which are more specific for different types of documents, are defined in the classes. Others for a specific purpose are define in the macro packages.

A good example is the macro for the bibliography or references heading. In the »article« class the references section title ("References") is stored in the macro \refname. The title for the bibliography chapter ("Bibliography")in the »book« (or »report«) class is stored in the macro \bibname.

Macros which are not part of vanilla LaTeX are of course defined by packages. A possible pitfall is that some packages define the same macro.

As you can see, it is not always obvious where a macro is defined. That's one reason why we mostly like to see a minimal example here added to a question in order to see where possible clashes are caused.


Thorsten
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Location of Macro Definition

Post by Stefan Kottwitz »

With some experience one can know where a macro may be defined or can easily locate it.

Sometime it's hard though, in such cases I use a shell script

Code: Select all

#!/bin/bash
# texgrep - searches for a text pattern contained in files
#   located inside the texmf trees
# usage: texgrep pattern [extension]
# usage examples:
#   texgrep phantomsection sty
#   texgrep \\\\def\\\\phantomsection
# Stefan Kottwitz, 2008
if [ $# -eq 0 ]; then
  echo 1>&2 Usage: texgrep pattern [extension]
  exit 1
fi
for path in TEXMFMAIN TEXMFDIST TEXMFHOME
do
 find `kpsewhich --var-value=$path` -name "*$2" |xargs grep $1
done
exit 0
I described it here in my blog: Speed up the work by shell scripts.

Stefan
LaTeX.org admin
wcw
Posts: 20
Joined: Thu Mar 08, 2012 12:35 pm

Location of Macro Definition

Post by wcw »

localghost wrote:Macros are defined at different places. Those which are essential for every document are defined in the LaTeX kernel (files with suffix *.ltx). Macros like \figurename, which are more specific for different types of documents, are defined in the classes. Others for a specific purpose are define in the macro packages.

A good example is the macro for the bibliography or references heading. In the »article« class the references section title ("References") is stored in the macro \refname. The title for the bibliography chapter ("Bibliography")in the »book« (or »report«) class is stored in the macro \bibname.

Macros which are not part of vanilla LaTeX are of course defined by packages. A possible pitfall is that some packages define the same macro.

As you can see, it is not always obvious where a macro is defined. That's one reason why we mostly like to see a minimal example here added to a question in order to see where possible clashes are caused.


Thorsten
Thanks for your reply.
wcw
Posts: 20
Joined: Thu Mar 08, 2012 12:35 pm

Location of Macro Definition

Post by wcw »

Stefan_K wrote:With some experience one can know where a macro may be defined or can easily locate it.

Sometime it's hard though, in such cases I use a shell script

Code: Select all

#!/bin/bash
# texgrep - searches for a text pattern contained in files
#   located inside the texmf trees
# usage: texgrep pattern [extension]
# usage examples:
#   texgrep phantomsection sty
#   texgrep \\\\def\\\\phantomsection
# Stefan Kottwitz, 2008
if [ $# -eq 0 ]; then
  echo 1>&2 Usage: texgrep pattern [extension]
  exit 1
fi
for path in TEXMFMAIN TEXMFDIST TEXMFHOME
do
 find `kpsewhich --var-value=$path` -name "*$2" |xargs grep $1
done
exit 0
I described it here in my blog: Speed up the work by shell scripts.

Stefan
I have copied thse code to the latex software and complied. But it failed. Can you tell me the method to use these codes? For example, where should I place these codes and run?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Location of Macro Definition

Post by Stefan Kottwitz »

This software is not related to LaTeX. It's a shell script. The example above runs on the bash shell, but can be used on other shells as well. It's for use at the command prompt, i.e. in a terminal window. On a Linux (or Unix system) or Mac OS X ist should run without further installations - having a good shell is an important reason for me to work with Linux. If you use Windows, you would need additional software, such as Cygwin. The TeX tools such as kpsewhich and texdoc also work on windows, but in this shell script I used typical unix tools such as find, xargs and grep.

This was for basic information. Details depend on your operating system.

Stefan
LaTeX.org admin
wcw
Posts: 20
Joined: Thu Mar 08, 2012 12:35 pm

Location of Macro Definition

Post by wcw »

Stefan_K wrote:This software is not related to LaTeX. It's a shell script. The example above runs on the bash shell, but can be used on other shells as well. It's for use at the command prompt, i.e. in a terminal window. On a Linux (or Unix system) or Mac OS X ist should run without further installations - having a good shell is an important reason for me to work with Linux. If you use Windows, you would need additional software, such as Cygwin. The TeX tools such as kpsewhich and texdoc also work on windows, but in this shell script I used typical unix tools such as find, xargs and grep.

This was for basic information. Details depend on your operating system.

Stefan
That is cool! I could try installing the Linux on my PC!
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Location of Macro Definition

Post by Stefan Kottwitz »

I use Ubuntu Linux and I'm very satisfied with it. A recommendation: installing TeX from Linux repositories, from the operating system package manager, is very easy. But if you would like to have the most current TeX version, install TeX Live 2011 via internet (just click that link and read). That's what I usually do.

Stefan
LaTeX.org admin
Post Reply