2

I want to automatically add a \, between the upperlimit and the integral sign instead of having to type it mannually every time. I'm using latexocr to snip the equation and copy the latex code from latexocr to my document, if i use \renewcommand to redefine \int, then the syntax would become \int{a}{b}{f} but i want to keep the \int_{a}^{b}{f} format where _ and ^ is used to indicate upper and lower limit. Are there anyway to achieve this or are there any method to configure the default spacing of the original \int command ?

\let\st\int
\renewcommand*{\int}[3]{\st_{#1}^{\,#2}{#3}}

% but i want something like this
$\int_{a}^{b}{s}(x)dx$
% instead of this
$\int{a}{b}{s}(x)dx$
2
  • Welcome to TeX.SE.
    – Mico
    Sep 8 at 6:52
  • And why do you want that? The default spacing looks better IMO.
    – Gaussler
    Sep 8 at 8:28

2 Answers 2

1

Assuming you really want to do this, it is a job for \RenewDocumentCommand and its embellishment argument type.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\RenewDocumentCommand{\int}{t{\limits}e{_^}}{%
  \DOTSI\intop\ilimits@
  \IfBooleanT{#1}{\limits}
  \IfValueT{#2}{_{#2}}%
  \IfValueT{#3}{^{\IfBooleanF{#1}{\,}#3}}%
}
% just for comparison
\newcommand{\standardint}{\DOTSI\intop\ilimits@}
\makeatother

\begin{document}

\begin{gather*}
\int\limits_{a}^{b}f(t)\,dt
\int_{a}^{b}f(t)\,dt
\\
\standardint_{a}^{b}f(t)\,dt
\end{gather*}

\end{document}

You do use amsmath, don't you?

enter image description here

By the way, the syntax for \int doesn't require braces around the integrand as you seem to believe: they're actually generally unwanted.

2

You need to employ the Plain-TeX \def directive instead of the LaTeX \renewcommand directive. That said, I would define the new version of \int to take two arguments rather than three, as the version of the \int macro mentioned in the OP's query does nothing special with the third argument.

enter image description here

\documentclass{article}

\let\st\int
\def\int_#1^#2{\st_{#1}^{\,#2}}

\begin{document}
$\int_a^b s(x)dx$ \quad $\int_{u}^{v} w(x)\,dx$
\end{document} 

You must log in to answer this question.

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