# Long enough vertical bar | depending on expression before and after it - Elliptic integral

I want to write an elliptic integral F(\phi|k^2) with different expressions for \phi and k^2 including fractions. So I want a new command (macro?) for this. It should look like e.g. \F{\phi}{k^2}. This is no problem at all, without scaling the vertical bar |. But I want to autoscale it with the arguments.

What can I do to create a new command like this? Do I have to go the long way by trying to determine the height of the arguments? How would this look alike?

• I suggest that you have a look to the mathtools package, subsection 3.6. Edit: “fractals”? Or do you mean “fractions”? – GuM Nov 28 '16 at 22:15
• @GustavoMezzetti Yes, you are right, sorry - edited my post. – nox Nov 28 '16 at 22:20

Following up on @GustavoMezzetti's comment, here's a solution that makes use of the \DeclarePairedDelimiterX macro of the mathtools package.

Aside: You may want to come up with a mnemonic macro name than "\F".

\documentclass{article}
\usepackage{mathtools}
% See p. 27 of the user guide of the 'mathtools' package
% for the source of the following code
\providecommand\given{}
\newcommand\SetSymbol[1][]{%
\nonscript\:#1\vert
\allowbreak
\nonscript\:
\mathopen{}}
\DeclarePairedDelimiterX\PSet[1]\lparen\rparen{%
\renewcommand\given{\SetSymbol[\delimsize]}#1}
\newcommand\F[2]{F\PSet*{#1\given #2}}

\begin{document}
$\F{\phi}{k} \quad \F{\phi}{k^2} \quad \F{\phi}{\frac{u}{v}}$
\end{document}


Addendum: As @egreg has pointed out in comment, using \DeclarePairedDelimiterX in the definition of the \F macro may be sort of overkill, as no use is made of the optional argument to specify fixed-sized fences. A more streamlined version of the \F macro would therefore be:

\newcommand{\F}[2]{%
F\mleft(#1\nonscript\:\middle\vert\nonscript\:‌​#2\mright)}


With this approach, it's necessary to load the mleftright package for its \mleft and \mright macros. On the other hand, it's no longer necessary to load the mathtools package.

A full MWE:

\documentclass{article}
\usepackage{mleftright} % for "\mleft" and "\mright" macros
\newcommand{\F}[2]{%
F\mleft(#1\nonscript\:\middle\vert\nonscript\:‌​#2\mright)}
\begin{document}
$\F{\phi}{k} \quad \F{\phi}{k^2} \quad \F{\phi}{\frac{u}{v}}$
\end{document}

• I don't understand why doing all that work, when at the end you always use the “expanding” version. Just \newcommand{\F}[2](F\mleft(#1\nonscript\:\middle\nonscript\:#2\mright)} would do the same (with mleftright). – egreg Nov 29 '16 at 0:04
• @egreg - I'm afraid I get a cryptic Missing \begin{document} when I try to implement your approach. (Yes, I do load the mleftright package.) – Mico Nov 29 '16 at 6:29
• Typo: ( instead of { before F – egreg Nov 29 '16 at 10:00
• @egreg - Thanks! I've posted an addendum to post your suggestion, fixing a second issue along the way (missing \vert after \middle). – Mico Nov 29 '16 at 12:52
• Allow me to recall my point of view on how such constructions should be implemented in order to get the correct spacing in all situations (inserting a suitable combination of math atoms, instead of relying on explicit space commands). – GuM Dec 2 '16 at 21:03

A simple implementation with a perhaps more natural syntax:

\documentclass{article}
\usepackage{mathtools}

\DeclarePairedDelimiterX{\EllInner}[1]{(}{)}{%
\renewcommand{\with}{\,\delimsize|\,}%
#1%
}
\newcommand{\Ell}{F\EllInner}
\providecommand{\with}{}

\begin{document}

$\Ell{\varphi\with k^2} = \int_0^\varphi\frac{dt}{\sqrt{1-k^4\sin^2t}} \qquad \Ell*{\frac{\pi^2}{4}\with k^2} \qquad \Ell[\Big]{\frac{\pi^2}{4}\with k^2}$

\end{document}


If you prefer the two argument syntax, you can do with

\documentclass{article}
\usepackage{mathtools}

\DeclarePairedDelimiterX{\EllInner}[2]{(}{)}{%
#1\,\delimsize|\,#2%
}
\newcommand{\Ell}{F\EllInner}

\begin{document}

$\Ell{\varphi}{k^2} = \int_0^\varphi\frac{dt}{\sqrt{1-k^4\sin^2t}} \qquad \Ell*{\frac{\pi^2}{4}}{k^2} \qquad \Ell[\Big]{\frac{\pi^2}{4}}{k^2}$

\end{document}


You can also use | as the inner separator, with a slick trick. The caveat is that the expressions must not contain |, but they can contain \vert, \lvert or \rvert.

\documentclass{article}
\usepackage{mathtools}

\DeclarePairedDelimiterX{\EllInner}[1]{(}{)}{\activatebar #1}
\newcommand{\Ell}{F\EllInner}
\newcommand{\activatebar}{%
\begingroup\lccode~=| \lowercase{\endgroup\def~}{\,\delimsize\vert\,}%
\mathcode|="8000
}

\begin{document}

$\Ell{\varphi | k^2} = \int_0^\varphi\frac{dt}{\sqrt{1-k^4\sin^2t}} \qquad \Ell*{\frac{\pi^2}{4} | k^2} \qquad \Ell[\Big]{\frac{\pi^2}{4} | k^2}$

\end{document}


Also with mathtools, I define a \Fellcommand with DeclarePairedDelimiterXPP which takes two arguments. The \Fell* command adds a pair of implicit \left···\right, and the optional argument in \Fell (\big, \Big, &c.) allows to fine-tune the size of the delimiters.

A variant which relies on xparse, named \fell, uses only one argument in two parts separated by a semicolon, so the syntax is closer to what one writes by hand.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{lmodern}
\usepackage{mathtools}
\DeclarePairedDelimiterXPP\Fell[2]{\mathrm{F}}(){}%
{#1\,\delimsize\vert\,\mathopen{}#2}

\usepackage{xparse}

\DeclarePairedDelimiterXPP{\Fel}[1]{\mathrm{F}}(){}%
{\Felargs{#1}}
\NewDocumentCommand{\Felargs}{>{\SplitArgument{1}{;}}m}
{\Felargsaux#1}
\NewDocumentCommand{\Felargsaux}{mm}
{#1\,\delimsize\vert\,\mathopen{}#2}%

\begin{document}

$\Fell{\varphi}{ k^2} = \int_0^\varphi\frac{\mathrm d\mkern1mu t}{\sqrt{1-k^4\sin^2t}}\qquad\Fell*{\frac{\pi^2}{4}}{k^2} \qquad\Fell[\Big]{\frac{\pi^2}{4}}{k^2}$%

$\Fel{\varphi ; \ell} = \int_0^\varphi\frac{\mathrm d\mkern1mu t}{\sqrt{1-\ell^2\sin^2t}}\qquad\Fel*{\frac{\pi^2}{4}; \ell}\qquad\Fel[\Big]{\frac{\pi^2}{4}; \ell}$%

\end{document}
`