What is the difference between a macro with no arguments and a name?

  • LaTeX
  • Thread starter Eclair_de_XII
  • Start date
  • Tags
    Difference
In summary, the conversation discusses the difference between the name and macro forms of linking to a website in LaTeX. The two forms, \PFlink and \linkToPF, are functionally equivalent and perform the same task of linking to PhysicsForums.com. However, the use of \def in \PFlink is discouraged in LaTeX, as it is a low-level TeX command.
  • #1
Eclair_de_XII
1,083
91
TL;DR Summary
Quick question. Title gives the most straight-forward version of it.
This is some sample code that I drew up.

The name is "\PFlink"
The macro is "\linktoPF"

My question is this: Would you be able to tell which is the name and which is the macro without referring to their respective definitions in the pre-amble below?

Code:
\documentclass{article}

\usepackage{hyperref}

\def\PFlink{\href{https://www.physicsforums.com/}{Welcome to Physics Forums!}}
\newcommand{\linkToPF}{\href{https://www.physicsforums.com/}{Welcome to Physics Forums!}}

\begin{document}

    \paragraph{Names vs. Macros}
        These are links to PhysicsForums.com. One of them is in the form of a name and the other in the form of a macro.
        \begin{description}
            \item[name] \PFlink
            \item[macro] \linkToPF
        \end{description}

\end{document}

Functionality-wise, they both seem to do exactly the same thing: link to this site. Are they different in any way, or no? If so, how would you show someone that they are different without telling the arbitrary novice to just look at the definitions of them in the pre-amble?
 
Physics news on Phys.org
  • #2
The two are functionally equivalent.

This same phenomenon occurs in symbolic logic, where the objects one works with in a language are predicates (eg '='), functions (eg '+'), variables (eg '##x##') and constants (eg '1'), but the concept of constant is redundant because a constant is just a function with no arguments (a 0-ary function, or function with arity zero, in logic jargon). That is, it requires no inputs, and always gives the same output.
 

Question 1: What is a macro with no arguments?

A macro with no arguments is a type of macro that does not require any input values or parameters to be passed into it. It can be thought of as a standalone function that performs a specific task without needing any external information.

Question 2: What is a named macro?

A named macro is a type of macro that has a unique name assigned to it. This allows the macro to be called and used multiple times throughout a program without having to rewrite the entire code each time. It also allows for easier editing and debugging of the macro's code.

Question 3: What is the difference between a macro with no arguments and a named macro?

The main difference between a macro with no arguments and a named macro is that a macro with no arguments does not require any input parameters, while a named macro can have input parameters. Additionally, a named macro can be called and used multiple times, while a macro with no arguments is a standalone function that can only be used once.

Question 4: When should I use a macro with no arguments?

A macro with no arguments is useful when you need to perform a specific task that does not require any external information or input parameters. It can also be used when you want to simplify your code and avoid having to repeat the same lines of code multiple times.

Question 5: When should I use a named macro?

A named macro is useful when you need to perform a task that requires input parameters or when you want to reuse the same code multiple times throughout a program. It also allows for easier editing and debugging of the code, making it a useful tool for larger and more complex programs.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
11K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
732
  • Programming and Computer Science
Replies
1
Views
629
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
275
Replies
59
Views
6K
Replies
1
Views
814
  • Feedback and Announcements
Replies
21
Views
2K
Replies
11
Views
2K
Back
Top