4

I'm trying to create a new command of the form,

\gradeq{T,x,y,z}

That takes the four arguments provided and displays,

\pdv{T}{x}\xhat + \pdv{T}{y}\yhat + \pdv{T}{z}\zhat

This is how I've tried it,

\newcommand{\gradeq}[4]{\pdv{#1}{#2}\xhat + \pdv{#1}{#3}\yhat + \pdv{#1}{#4}\zhat}

I've tried with extra curly braces as someone recommended in another question, and I've tried placing the command within $ ... $.

I get a whole list of errors. The full test document is,

\documentclass{article}

\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{physics}

\renewcommand{\abstractname}{Summary}
\renewcommand{\contentsname}{Outline}

% Frequently Used Math Symbols

% VECTORS
\newcommand{\xhat}{\hat{x}}
\newcommand{\yhat}{\hat{y}}
\newcommand{\zhat}{\hat{z}}

% VECTOR OPERATORS
\newcommand{\gradeq}[4]{\pdv{#1}{#2}\xhat + \pdv{#1}{#3}\yhat + \pdv{#1}{#4}\zhat}

\begin{document}

$\gradeq{T,x,y,z}$

\end{document}

And I receive the following errors, (All on line 25)

! Missing } inserted.
! Too many }'s. \frac #1#2->{\begingroup #1\endgroup \@@over #2}
! Missing $ inserted.
! Missing \endcsname inserted.
! Extra }, or forgotten $.

Note that the \xhat commands work in other documents, and \pdv is a command provided in the physics package that is meant to give the partial derivative in fraction form.

I'm brand new to LaTeX, so I'm sure I'm doing a whole host of things incorrectly.

1 Answer 1

7

Hi and welcome in the TeX.SE community. The mistake is for the command \gradeq. You should to use $\gradeq{T}{x}{y}{z}$ instead to put the commas $\gradeq(T,x,y,z)$ when you introduced many arguments. After it is not preferible to use physics package for problem for the spacing and unusual macro.

enter image description here

\documentclass{article}

\usepackage{amsmath,amssymb}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{physics}

\renewcommand{\abstractname}{Summary}
\renewcommand{\contentsname}{Outline}

% Frequently Used Math Symbols

% VECTORS
\newcommand{\xhat}{\hat{x}}
\newcommand{\yhat}{\hat{y}}
\newcommand{\zhat}{\hat{z}}

% VECTOR OPERATORS
\newcommand{\gradeq}[4]{\pdv{#1}{#2}\xhat + \pdv{#1}{#3}\yhat + \pdv{#1}{#4}\zhat}

\begin{document}

$\gradeq{T}{x}{y}{z}$

\end{document}
2
  • 1
    This works perfectly! Thank you for the quick and easy to comprehend response. Mar 27, 2021 at 22:05
  • 1
    Hi, remember that I am a scarce user :-).....especially in English language because I'm an Italian native speaker. If you have understood my synthetic explanation I am very very happy. Best regards.
    – Sebastiano
    Mar 27, 2021 at 22:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .