5

Preliminary note: I don't think this question is completely or even to a large extent subjective, as it seeks how to achieve objective utilitarian goals. Please read:

I am solving my QFT assignments in LaTeX. They're basically just a succession of questions and answers and I would be interested in your opinions on how to best make it clear to the reader if text belongs to a question or gives an answer.

In the past, I've written the whole question in italics, as in

\newcommand{\question}[1]{\itshape #1}

However, I never found this to be satisfactory, as it makes the questions harder to read and the entire page layout seem quite disrupted. Suggestions?

Edit: Manuel asked for a compilable example, so here you go. I stripped pretty much every bit of code not essential off of the following. Note that the answer to b) is hard to discern from the list of questions.

enter image description here

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{microtype}

\usepackage[a4paper,margin=25mm]{geometry}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[range-units = single]{siunitx}
\sisetup{detect-all,per-mode=fraction}

\usepackage[inline]{enumitem}
\setlist[enumerate]{leftmargin=0ex,label=\alph*)}
\setlist[itemize,1]{leftmargin=*}


\setlength{\parindent}{0ex}


\renewcommand{\vec}[1]{\boldsymbol{#1}}
\newcommand{\der}{\operatorname{d\!}{}}
\newcommand{\spint}[1][x]{\int_{\mathbb{R}^3} \! \der^3#1 \,}
\newcommand{\moint}{\int_{\mathbb{R}^3} \! \frac{\der^3p}{\(\num{2}\pi\)^{\num{3}}} \,}
\newcommand{\vnabla}{\vec{\nabla}}
\renewcommand{\(}{\left(}
\renewcommand{\)}{\right)}
\renewcommand{\[}{\left[}
\renewcommand{\]}{\right]}
\let\phi\varphi



\begin{document}

\section{Canonical commutation relations}

Starting from the mode expansion of the Schrödinger fields
\begin{align}
&\phi\(\vec{x}\) = \moint \frac{\num{1}}{\sqrt{\num{2}\omega_{\vec{p}}}} \(a\(\vec{p}\)e^{i\vec{p}\vec{x}} + a^\dagger\(\vec{p}\)e^{-i\vec{p}\vec{x}}\), \\
\text{and} \quad &\pi\(\vec{x}\) = \moint (-i) \sqrt{\frac{\omega_{\vec{p}}}{\num{2}}} \(a\(\vec{p}\)e^{i\vec{p}\vec{x}} - a^\dagger\(\vec{p}\)e^{-i\vec{p}\vec{x}}\),
\end{align}
we’ll derive the canonical commutation relations for the modes $a\(\vec{p}\)$ and $a^\dagger\(\vec{p}\)$ using the steps below.
\begin{enumerate}
\item Perform a Fourier transformation to deduce the relation between the Fourier modes $\tilde{\phi}\(\vec{p}\)$, $\tilde{\pi}\(\vec{p}\)$, and the modes $a\(\vec{p}\)$ and $a^\dagger\(\vec{p}\)$.
\item Derive the commutation relations
\begin{equation}
\[\tilde{\phi}\(\vec{p}\),\tilde{\pi}\(\vec{q}\)\] = i \(\num{2}\pi\)^{\num{3}} \delta^{\(\num{3}\)}\(\vec{p} + \vec{q}\)
\end{equation}
from the canonical commutation relations for $\phi\(\vec{x}\)$ and $\pi\(\vec{x}\)$.

%%%%%% All text belongs to questions except for this block. %%%%%%
The canonical commutation relations for $\phi\(\vec{x}\)$ and $\pi\(\vec{x}\)$ states that $\[\phi\(\vec{x}\),\pi\(\vec{y}\)\] = i \delta^{\(\num{3}\)}\(\vec{x} - \vec{y}\)$. Therefore
\begin{equation}
\begin{aligned}
\[\tilde{\phi}\(\vec{p}\),\tilde{\pi}\(\vec{q}\)\]
&= \spint\spint[y] e^{-i\vec{p}\vec{x}} e^{-i\vec{p}\vec{y}} \underbrace{\[\phi\(\vec{x}\),\pi\(\vec{y}\)\]}_{i \delta^{\(\num{3}\)}\(\vec{x} - \vec{y}\)} \\
&= i \spint e^{-i\(\vec{p}+\vec{q}\)\vec{x}}
= i \(\num{2}\pi\)^{\num{3}} \delta^{\(\num{3}\)}\(\vec{p} + \vec{q}\)
\end{aligned}
\end{equation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\item Conclude that
\begin{equation}
\[a\(\vec{p}\),a^\dagger\(\vec{q}\)\] = \(\num{2}\pi\)^{\num{3}} \delta^{\(\num{3}\)}\(\vec{p} - \vec{q}\)
\quad \text{and} \quad
\[a\(\vec{p}\),a\(\vec{q}\)\] = \[a^\dagger\(\vec{p}\),a^\dagger\(\vec{q}\)\] = \num{0}.
\end{equation}
\end{enumerate}

\end{document}

Update: Two images in response to Peter Grill's solution.

enter image description here enter image description here

Janosh
  • 4,042
  • 1
    A full compilable example with full example questions/answers so you we can have an idea of what you are up to would be great. – Manuel Oct 23 '14 at 19:59
  • have a look into the exsheets documentary – MaxNoe Oct 23 '14 at 20:01
  • You should typeset twocolumn questions, or balancing across two pages. LaTeX isn't proficient at this, but with proper effort you can get it done and I always had good experiences with it. – 1010011010 Oct 23 '14 at 20:09
  • Perhaps one of the solutions at Environments for visually setting text apart would work for you. Personally I would use an mdframed box with different background colors to distinguish the question and answer portion. – Peter Grill Oct 23 '14 at 20:20
  • @MaxNoe This looks useful. It seems sometimes like there is a LaTeX package for every purpose. Then again there are other times... ah, let's not get into those. – Janosh Oct 23 '14 at 20:45
  • Thanks for providing a MWE, but can you also mark which potions you consider \question and which you consider \answer? – Peter Grill Oct 23 '14 at 21:17
  • @PeterGrill Sure. – Janosh Oct 23 '14 at 21:21
  • @PeterGrill Isn't it a bad idea to redefine LaTeX's markup for beginning and ending maths mode? [I'm not picking on you! But I can only ping one person and I figure you will know....] – cfr Oct 24 '14 at 02:01
  • 1
    @cfr: Yeah, I think it is a bad idea -- I personally would not do it. But that isn't the thrust of this question -- perhaps would be as a new question though. – Peter Grill Oct 24 '14 at 17:04
  • Since the questions seem to be short and the answers long, consider boxing the former and using plain text for the latter. Then page breaks in a box would be less likely, and possibly easily preventable. – Ethan Bolker Oct 24 '14 at 18:17

1 Answers1

4

Here is an example of using mdframed to highlight the answer portion:

enter image description here

References:

Code:

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[english]{babel} \usepackage{microtype}

\usepackage[a4paper,margin=25mm]{geometry}

\usepackage{amsmath} \usepackage{amssymb} \usepackage[range-units = single]{siunitx} \sisetup{detect-all,per-mode=fraction}

\usepackage[inline]{enumitem} \setlist[enumerate]{leftmargin=0ex,label=\alph)} \setlist[itemize,1]{leftmargin=}

\setlength{\parindent}{0ex}

\renewcommand{\vec}[1]{\boldsymbol{#1}} \newcommand{\der}{\operatorname{d!}{}} \newcommand{\spint}[1][x]{\int_{\mathbb{R}^3} ! \der^3#1 ,} \newcommand{\moint}{\int_{\mathbb{R}^3} ! \frac{\der^3p}{(\num{2}\pi)^{\num{3}}} ,} \newcommand{\vnabla}{\vec{\nabla}} \renewcommand{(}{\left(} \renewcommand{)}{\right)} \renewcommand{[}{\left[} \renewcommand{]}{\right]} \let\phi\varphi

\usepackage{xcolor} \usepackage{mdframed} \newmdenv[% leftmargin=-5pt, rightmargin=-5pt, innerleftmargin=5pt, innerrightmargin=5pt, backgroundcolor=brown!10, ]{Answer}%

\begin{document}

\section{Canonical commutation relations}

Starting from the mode expansion of the Schrödinger fields \begin{align} &\phi(\vec{x}) = \moint \frac{\num{1}}{\sqrt{\num{2}\omega_{\vec{p}}}} (a(\vec{p})e^{i\vec{p}\vec{x}} + a^\dagger(\vec{p})e^{-i\vec{p}\vec{x}}), \ \text{and} \quad &\pi(\vec{x}) = \moint (-i) \sqrt{\frac{\omega_{\vec{p}}}{\num{2}}} (a(\vec{p})e^{i\vec{p}\vec{x}} - a^\dagger(\vec{p})e^{-i\vec{p}\vec{x}}), \end{align} we’ll derive the canonical commutation relations for the modes $a(\vec{p})$ and $a^\dagger(\vec{p})$ using the steps below. \begin{enumerate} \item Perform a Fourier transformation to deduce the relation between the Fourier modes $\tilde{\phi}(\vec{p})$, $\tilde{\pi}(\vec{p})$, and the modes $a(\vec{p})$ and $a^\dagger(\vec{p})$. \item Derive the commutation relations \begin{equation} [\tilde{\phi}(\vec{p}),\tilde{\pi}(\vec{q})] = i (\num{2}\pi)^{\num{3}} \delta^{(\num{3})}(\vec{p} + \vec{q}) \end{equation} from the canonical commutation relations for $\phi(\vec{x})$ and $\pi(\vec{x})$.

\begin{Answer} %%%%%% All text belongs to questions except for this block. %%%%%% The canonical commutation relations for $\phi(\vec{x})$ and $\pi(\vec{x})$ states that $[\phi(\vec{x}),\pi(\vec{y})] = i \delta^{(\num{3})}(\vec{x} - \vec{y})$. Therefore \begin{equation} \begin{aligned} [\tilde{\phi}(\vec{p}),\tilde{\pi}(\vec{q})] &= \spint\spint[y] e^{-i\vec{p}\vec{x}} e^{-i\vec{p}\vec{y}} \underbrace{[\phi(\vec{x}),\pi(\vec{y})]}_{i \delta^{(\num{3})}(\vec{x} - \vec{y})} \ &= i \spint e^{-i(\vec{p}+\vec{q})\vec{x}} = i (\num{2}\pi)^{\num{3}} \delta^{(\num{3})}(\vec{p} + \vec{q}) \end{aligned} \end{equation} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \end{Answer}

\item Conclude that \begin{equation} [a(\vec{p}),a^\dagger(\vec{q})] = (\num{2}\pi)^{\num{3}} \delta^{(\num{3})}(\vec{p} - \vec{q}) \quad \text{and} \quad [a(\vec{p}),a(\vec{q})] = [a^\dagger(\vec{p}),a^\dagger(\vec{q})] = \num{0}. \end{equation} \end{enumerate} \end{document}

Peter Grill
  • 223,288
  • This looks really nice. I wondered what happens, when an answer spans multiple pages. Tested it and actually, that worked well. However, there are some issues with this approach. I changed my margins a little and now some math is sticking out of the box. This also happens when using \smash to prevent automatically resized brackets from allowing for \underbraces. So perhaps even though it looks good, it is not a very robust solution. See the added image in my question for clarification. – Janosh Oct 24 '14 at 17:44
  • @PacificOrion: That problem you mention with smash can happen with regular text as well -- the surrounding text somehow needs to know about that vertical space that was taken up. Try adding normal text afterwards and you'll notice that the vertical space is shorter than it is in normal display mode equations. Or make the \smashed content several lines high; the problem will be even more obvious. IMHO that is not a problem with using this proposed solution, it is a problem in using \smash and requires that the surrounding text know about it. If you post the full code I can try have a look. – Peter Grill Oct 24 '14 at 18:01
  • You're right. In this particular instance, the following text had sufficient vertical distance for this to not show. After posting my comment, I fixed this problem by using a \vphantom after the brackets. I guess, the other issue is due to how LaTeX handles inline math expressions and probably requires manual tinkering. Or do you have any idea on a fix for that? – Janosh Oct 24 '14 at 18:12
  • @PacificOrion: Without seeing exactly how you are changing the margins it is difficult to help you. I'd suggest you compose a fully compilable MWE including \documentclass and the appropriate packages that reproduces the problem, and post a new question. – Peter Grill Oct 24 '14 at 18:29
  • Perhaps one more question: Can this be made to work with the enumerate environment so as to highlight the questions rather than the answers? When trying to include an item's counter in the highlighted box by placing \item within the Answer environment, LaTeX returns 'Something's wrong--perhaps a missing \item.'. – Janosh Dec 07 '14 at 11:21
  • @PacificOrion: I think you need to look into the resume option from the enumitem package, but I think this really should be a separate question. – Peter Grill Dec 08 '14 at 05:16