% !TEX TS-program = pdflatex
% !TEX encoding = UTF-8 Unicode

% This is a simple template for a LaTeX document using the "article" class.
% See "book", "report", "letter" for other types of document.

\documentclass[11pt]{article} % use larger type; default would be 10pt

\usepackage[utf8]{inputenc} % set input encoding (not needed with XeLaTeX)

%%% Examples of Article customizations
% These packages are optional, depending whether you want the features they provide.
% See the LaTeX Companion or other references for full information.

\usepackage{geometry} % to change the page dimensions
\geometry{a4paper} % or letterpaper (US) or a5paper or....
% \geometry{margin=2in} % for example, change the margins to 2 inches all round
% \geometry{landscape} % set up the page for landscape
%   read geometry.pdf for detailed page layout information

\usepackage{graphicx} % support the \includegraphics command and options

% \usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent

\usepackage{booktabs} % for much better looking tables
\usepackage{array} % for better arrays (eg matrices) in maths
\usepackage{paralist} % very flexible & customisable lists (eg. enumerate/itemize, etc.)
\usepackage{verbatim} % adds environment for commenting out blocks of text & for better verbatim
\usepackage{subfig} % make it possible to include more than one captioned figure/table in a single float
\usepackage{amsmath} % allow the usage of math symbols, and tools
% These packages are all incorporated in the memoir class to one degree or another...

\usepackage{fancyhdr} % This should be set AFTER setting up the page geometry
\pagestyle{fancy} % options: empty , plain , fancy
\renewcommand{\headrulewidth}{0pt} % customise the layout...

\allsectionsfont{\sffamily\mdseries\upshape} % (See the fntguide.pdf for font help)
% (This matches ConTeXt defaults)

%%% ToC (table of contents) APPEARANCE
\usepackage[nottoc,notlof,notlot]{tocbibind} % Put the bibliography in the ToC
\usepackage[titles,subfigure]{tocloft} % Alter the style of the Table of Contents
\renewcommand{\cftsecpagefont}{\rmfamily\mdseries\upshape} % No bold!

%%% END Article customizations

%%% The "real" document content comes below...

\title{Differential Equations}
\author{Jose M. Serra Jr.}
%\date{} % Activate to display a given date or no date (if empty),
         % otherwise the current date is printed 

%%Newcommands to ease the coding of the coding
\ifx \relax[1]\relax
    \begin{equation} #1 \end{equation}
\ifthenelse \relax[2]\relax
    \begin{equation} #1 \end{equation} \par
    \begin{equation} #2 \end{equation}
    \begin{equation} #1 \end{equation} \par
    \begin{equation} #2 \end{equation} \par
    \begin{equation} #3 \end{equation}

\textbf{Series Solutions of Linear Equations}
\textbf{Review of Power Series}


! Missing $ inserted.
<inserted text> 

I have a question pertaining to what is wrong with my new command? I read a post on the site, and they did something similar, so I tried doing one of my own, and it is not working.

  • \ifx \relax[ compares \relax and [ so it is always false, but you do not say what you want this code to do, nor provide a compete test file that shows any behaviour so it is hard to answer your question Apr 22, 2020 at 14:23
  • also apart from the \ifx syntax this code appears to be inserting \par before \begin{equation} display math should never start a paragraph TeX will generate a spurious empty first line of a paragraph above the display in that case. Apr 22, 2020 at 14:25
  • Ok ok hold on I am gonna upload the section Apr 22, 2020 at 14:25
  • why not simply use \begin{gather} eqn1 \\ eqn2 \\ eqn3 \end{gather} why do you need any tests? Apr 22, 2020 at 14:27
  • 1
    Why don't you say that in the question? but the standard syntax \begin{gather} aaa\\ bbb\\ccc \\ddd\end{gather} is much simpler and will handle any number of equations and does not force spurious paragraphs between the equations. So could answer what is wrong with the test but the actual use case should have no tests at all. Apr 22, 2020 at 14:37

1 Answer 1


The test

\ifx \relax[

tests the two tokens \relax and [ and as these are not equal it is always false.

Presumably you intended


which is better written as


which tests if #1 is empty (as if it is empty the two \relax tokens are compared, and equal)

But that would allow a syntax such as


the macro \formula would always have three arguments, You are just testing if the arguments are empty ({}) . So in



The three arguments are f(x), \par (from the blank line) and \end (intended for \end{document}).

Apart from these issues you are forcing \par before \begin{equation} but this always makes poor spacing.

It is better to use a multiline display, so allowing any number of lines with no tests.






  • stackoverflow.com/questions/2144176/… Do you think you can help me doing it this way? Apr 22, 2020 at 14:50
  • LaTeX optional arguments should use [...] not {...} (the xparse package makes it easy to define commands with optional arguments) but there is zero benefit to using such a syntax here, you restrict the number of lines supported and hide the latex syntax so will lose syntax highlighting and context sensitive support in your editor, and make debugging any errors in the math markup a lot harder.. Apr 22, 2020 at 14:53

You must log in to answer this question.

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