3

Following on from this question, I'd like to be able to do this but with an integral sign.

The proposed solution is the following:

\newcommand{\opA}{\mathop{\vphantom{\sum}\mathchoice
   {\vcenter{\hbox{\huge A}}} 
   {\vcenter{\hbox{\Large A}}}{\mathrm{A}}{\mathrm{A}}}\displaylimits}

I tried to modify this for an integral sign:

\newcommand{\integral}[2]{\mathop{\vphantom{\int}\mathchoice
    {\huge\int #1 \, d#2}
    {\Large\int #1 \, d#2}{\mathrm{A}}{\mathrm{A}}}\displaylimits}

Applying this via \integral{x}{x}_0^1 for instance then gives the following:

Example Integral

However, this centres the limits above and below the integral instead of where you want them at the left.

So my question is: how to align them in the right place? Also, what should I write instead of \mathrm{A} in the other two type modes that are shown above?

Thanks!

4

2 Answers 2

2

Easy but inflexible answer

\def\integral#1#2_#3^#4{\int_{#3}^{#4}\mathopen{}#1\mathclose{}\mathop{}\!d#4\mathclose{}}

And then you have to always use the command with the limits and in that order. So if you don't want limits you would need \integral{f(x)}{x}_{}^{}.


A better solution would be xparse, but I cannot try if it works correctly right now (if someone checks and it doesn't work I will remove it).

\usepackage{xparse}
\NewDocumentCommand\integral{ m m e{_^} }{\integralaux{#1}{#2}#3}
\NewDocumentCommand\integralaux{mmmm}
 {\int\IfValueT{#3}{_{#3}}\IfValueT{#4}{^{#4}}%
  \mathopen{}#1\mathclose{}\mathop{}\!d#2\mathclose{}}

With this second version, you can use with flexibility \integral{x}{x}, \integral{x}{x}_{a}, \integral{x}{x}^{a}, \integral{x}{x}_{a}^{b}, \integral{x}{x}^{a}_{b}.

Also, it's possible to do it with \@ifnextchar and classical LaTeX, and has already been done in this site.

2

You might do something like this, but note the name I gave to the new command.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse,relsize}

\NewDocumentCommand{\badint}{e{_^}}{%
  \mathop{
    \mathchoice
      {\displaystyle\mathlarger{\mathlarger{\int_{\mathsmaller{\mathsmaller{#1}}}^{\mathsmaller{\mathsmaller{#2}}}}}}
      {\textstyle\mathlarger{\int_{\mathsmaller{#1}}^{\mathsmaller{#2}}}}
      {\scriptstyle\mathlarger{\int_{\mathsmaller{#1}}^{\mathsmaller{#2}}}}
      {\scriptscriptstyle\mathlarger{\int_{\mathsmaller{#1}}^{\mathsmaller{#2}}}}
  }
}

\begin{document}
\[
\badint_0^1 f(x)\,dx \ne \int_0^1 f(x)\,dx
\qquad
\textstyle
\badint_0^1 f(x)\,dx \ne \int_0^1 f(x)\,dx
\]

\end{document}

I find the output really ugly.

enter image description here

You must log in to answer this question.

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