Math & Sciencenewcommand problem

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
juliette
Posts: 75
Joined: Thu Nov 20, 2008 10:15 pm

newcommand problem

Post by juliette »

Hello,

I'm wondering why my first line doesn't work, but the second one does ?

Code: Select all

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{mathrsfs}

\newcommand{\bra}[1]{\langle #1 |}
\newcommand{\ket}[1]{| #1 \rangle}
\newcommand{\ppp}[1]{\bra{\psi_0}}
\newcommand{\pp}[1]{\ket{\psi_0}}

\begin{document}

$F(t)=\ppp\rho(t)\pp$
$F(t)=\bra{\psi_0}\rho(t)\ket{\psi_0}$

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

newcommand problem

Post by localghost »

It's in the definition of the last two commands for the Dirac notation.

Code: Select all

\newcommand{\ppp}[1]{\bra{\psi_0}}
\newcommand{\pp}[1]{\ket{\psi_0}}
You say that there is to pass one argument, but there is no according parameter. You have to correct that.

Code: Select all

\newcommand{\ppp}{\bra{\psi_0}}
\newcommand{\pp}{\ket{\psi_0}}
The mathtools package offers a mechanism for an easier definition of such delimiter pairs.

Code: Select all

\documentclass[11pt]{article}
\usepackage{mathtools}  % loads »amsmath« subsequently

\DeclarePairedDelimiter{\bra}{\langle}{\rvert}
\DeclarePairedDelimiter{\ket}{\lvert}{\rangle}

\begin{document}
  $F(t)=\bra{\psi_0}\rho(t)\ket{\psi_0}$
\end{document}
The package manual has the details.


Best regards
Thorsten
juliette
Posts: 75
Joined: Thu Nov 20, 2008 10:15 pm

Re: newcommand problem

Post by juliette »

Thank you so much Thorsten!
That was very helpful! I will use your method from now on =)

juliette
Post Reply