4

I tried all answers in Spacing around \left and \right and none of them work.

I use code generate by computer CAS. And all the code generates \left(...\right). So not possible to do any manual editing of latex code generated.

Only issue is that something like f\left(x\right) adds extra space between function name f and the parentheses. I am not talking about any space inside parentheses, but the space outside between function name and starting (.

I only want this space to be the same as if code was written using f(x). Nothing else change.

First, here is MWE showing the issue

\documentclass[12pt]{article} 

\usepackage[T1]{fontenc}
\usepackage{kpfonts,baskervald}
\usepackage{amsmath}
\begin{document}
\begin{align*} 
  \int \frac{dy}{g(y)} &= \int f(x) \, dx\\ 
  \int \frac{dy}{g\left(y\right)} &= \int f\left(x\right) \, dx
\end{align*} 
\end{document}

Compiled with lualatex gives

enter image description here

Notice how the space after function name is larger when using \left(...\right) which is the second equation.

I'd like the space after function names and starting ( in the second equation to be same as first equation as it looks better.

Below are all my tries. Some of them fix the space after g and not after f and some solution fix the space after f but not after g.

But there is no solution which produce same exact output for second equation as the first one.

Try 1 (accepted answer in the above link)

\documentclass[12pt]{article} 
\let\originalleft\left
\let\originalright\right
\renewcommand{\left}{\mathopen{}\mathclose\bgroup\originalleft}
\renewcommand{\right}{\aftergroup\egroup\originalright}

\usepackage[T1]{fontenc}
\usepackage{kpfonts,baskervald}
\usepackage{amsmath}
\begin{document}
\begin{align*} 
  \int \frac{dy}{g(y)} &= \int f(x) \, dx\\ 
  \int \frac{dy}{g\left(y\right)} &= \int f\left(x\right) \, dx
\end{align*} 
\end{document}

Gives

enter image description here

Notice the space after g in second equation have become too small.

Try 2

\documentclass[12pt]{article} 
\usepackage[T1]{fontenc}
\usepackage{kpfonts,baskervald}
\usepackage{amsmath}
\usepackage{mathtools}
\DeclarePairedDelimiter\pars{\lparen}{\rparen}
\begin{document}
\begin{align*} 
  \int \frac{dy}{g(y)} &= \int f(x) \, dx\\ 
  \int \frac{dy}{g\left(y\right)} &= \int f\left(x\right) \, dx
\end{align*} 
\end{document}

Gives

enter image description here

No effect. Larger space after function names still exist.

Try 3

\documentclass[12pt]{article} 
\usepackage[T1]{fontenc}
\usepackage{kpfonts,baskervald}
\usepackage{amsmath}

\let\originalleft\left
\let\originalright\right
\def\left#1{\mathopen{}\originalleft#1}
\def\right#1{\originalright#1\mathclose{}}

\begin{document}

\begin{align*} 
  \int \frac{dy}{g(y)} &= \int f(x) \, dx\\ 
  \int \frac{dy}{g\left(y\right)} &= \int f\left(x\right) \, dx
\end{align*} 
\end{document}

Gives

enter image description here

Again, now space after g is too small.

Try 4

\documentclass[12pt]{article} 
\usepackage[T1]{fontenc}
\usepackage{kpfonts,baskervald}
\usepackage{amsmath}

\Umathopinnerspacing\displaystyle=0mu
\Umathopinnerspacing\textstyle=0mu
\begin{document}
\begin{align*} 
  \int \frac{dy}{g(y)} &= \int f(x) \, dx\\ 
  \int \frac{dy}{g\left(y\right)} &= \int f\left(x\right) \, dx
\end{align*} 
\end{document}

Gives

enter image description here

Still, the space between function names and ( is not same in second equation as first equation.

try 5

\documentclass[12pt]{article} 
\usepackage[T1]{fontenc}
\usepackage{kpfonts,baskervald}
\usepackage{amsmath}

\def\delim#1#2#3{
  \mathopen{\left#1 \vphantom{#2} \right.}
  \kern-\nulldelimiterspace #2 \kern-\nulldelimiterspace
  \mathclose{ \left. \vphantom{#2} \right#3 }
}
\begin{document}
\begin{align*} 
  \int \frac{dy}{g(y)} &= \int f(x) \, dx\\ 
  \int \frac{dy}{g\left(y\right)} &= \int f\left(x\right) \, dx
\end{align*} 
\end{document}

Gives

enter image description here

Still, the space between function names and ( is not same in second equation as first equation.

Try 6

\documentclass[12pt]{article} 
\usepackage[T1]{fontenc}
\usepackage{kpfonts,baskervald}
\usepackage{amsmath}
\usepackage{mleftright}
\renewcommand{\left}{\mleft}
\renewcommand{\right}{\mright}

\begin{document}
\begin{align*} 
  \int \frac{dy}{g(y)} &= \int f(x) \, dx\\ 
  \int \frac{dy}{g\left(y\right)} &= \int f\left(x\right) \, dx
\end{align*}         
\end{document}

Gives

enter image description here

The space after f looks same as in equation 1, but the space after g in second equation is now too small.

11
  • 1
    Just out of idle curiosity: Why are you writing \left(x\right)? Put differently, why aren't you writing (x)? Commented Feb 6 at 20:11
  • 2
    @Mico As I mentioned, this is code generated by computer. All code generates using \left( and \right. Commented Feb 6 at 20:13
  • 2
    @Nasser Change the faulty code… Commented Feb 6 at 20:14
  • 3
    @egreg It is not my code. As I mentioned. This is how computer CAS generates Latex code. Mathematica and Maple will not change this because I ask them to do so. I just need the space after function name and first ( to be smaller. ALso Scientific word do the same. It generates \left and \right) for everything. Commented Feb 6 at 20:15
  • 2
    as we have been saying for over a decade to your posts: the latex generated by maple and mathematica is generated by user definable functions you could simply fix it there Commented Feb 6 at 20:17

1 Answer 1

8

If code is faulty, change it…

Anyway, you should read the manual of mleftright.

% Source - https://tex.stackexchange.com/q/759338
% Posted by Nasser, modified by community. See post 'Timeline' for change history
% Retrieved 2026-02-06, License - CC BY-SA 4.0

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{kpfonts,baskervald}
\usepackage{amsmath}
\usepackage{mleftright}
\mleftright

\begin{document}

\begin{align*}
  \int \frac{dy}{g(y)} &= \int f(x) \, dx\\
  \int \frac{dy}{g\left(y\right)} &= \int f\left(x\right) \, dx
\end{align*}

\end{document}

output

3
  • Thanks. I did not know I could just do this. btw, this works in texlive, but in Miktex on windows 10 it does not work, i.e. space after g becomes too small. But since I use Linux and Texlive to compile this is not an issue. Commented Feb 6 at 20:25
  • 2
    Do you really need \usepackage{mleftright} to use \left and \right? Or does that give you a different \left and \right than the usual \left and \right? Commented Feb 7 at 7:18
  • 2
    @JosBergervoet The latter. The package provides \mleft and \mright, but the declaration \mleftright makes \left to be \mleft and \right to be \mright. Commented Feb 7 at 9:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.