# How to display negative limits for an integral in LaTeX? [closed]

I am having issues displaying negative limits for an integral.

My code is in Python:

f"Use substitution to evaluate the definite integral $_\\displaystyle\\int_{stra}^{strb} {latex(f)}\\,dx$_."


It displays like this:

• latex(f) returns sympy.latex(f)
• f = c*x*((d*x**2)+e)**g
• stra is the string version of a variable a which is an integer between -3 and 3.
• strb is the string version of a variable b which is an integer between -5 and 5.
• I made the variables strings to see if it made a difference as it was doing the same thing when the variables were integers.

## closed as off-topic by egreg, Stefan Pinnow, Phelype Oleinik, barbara beeton, TiuriOct 29 at 13:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center." – egreg, Stefan Pinnow, Phelype Oleinik, barbara beeton, Tiuri
If this question can be reworded to fit the rules in the help center, please edit the question.

• Welcome to TeX.SE. Please clarify how latex(f), stra, and strb are defined. – Mico Oct 15 at 16:18
• Are you missing the underscore? \int_{stra}? – Teepeemm Oct 15 at 16:50
• this seems to be a python rather than latex question, you need to generate \int_{-6}^{-34} not \int_-6^-34 (also you should not normally have \displaystyle in a document) – David Carlisle Oct 15 at 17:31
• Your problem kooks more a Python one than a LatTeX one. Using int_{{{stra}}}^{{{strb}}} instead of int_{stra}^{strb} should fix your problem. – projetmbc Oct 15 at 17:55
• Thanks projetmbc that did it! I'm very new to using latex with python so I wasn't sure which part I was getting wrong. – Gabi Oct 15 at 18:05

I'm not sure I understand your python code. But here's how I would input the integral expression using just simple TeX and LaTeX macros:

\documentclass{article} % or some other suitable document class
\begin{document}
$\int_{-6}^{-3} 4x{(17x^2+9)}^3\,dx \quad\mbox{or}\quad \int_{-6}^{-3}\!\! 4x{(17x^2+9)}^3\,dx$
\end{document}

• Observe that the second expression is very similar to the first. The only difference is that there is less whitespace between the integral symbol (including its limits) and the integrand. – Mico Oct 29 at 9:45

Since Python 3.6 f-strings (a string literal that is prefixed with f or F) provide a way to embed expressions inside string literals by including replacement fields, which are expressions delimited by curly braces {}. From the docs:

The parts of the string outside curly braces are treated literally, except that any doubled curly braces {{ or }} are replaced with the corresponding single curly brace.

So, if you want to interpolate an expression into a string literal that includes literal curly brace characters you will need three sets of braces as pointed out by @projetmbc in the comments.

There's no need to convert a and b to string.

# MWE

integral.py

import sympy

x = sympy.symbols('x')
a, b, c, d, e, g = -6, -3, 4, 17, 9, 3
f = c*x*((d*x**2) + e)**g

src = fr"""\documentclass{{standalone}}

\begin{{document}}
Use substitution to evaluate the definite integral
$\displaystyle\int_{{{a}}}^{{{b}}} {sympy.latex(f)}\,dx$.
\end{{document}}"""

with open('integral.tex', mode='w') as fobj:
print(src, file=fobj)


When the Python script above is run it generates the following file:

integral.tex

\documentclass{standalone}

\begin{document}
Use substitution to evaluate the definite integral
$\displaystyle\int_{-6}^{-3} 4 x \left(17 x^{2} + 9\right)^{3}\,dx$.
\end{document}


which renders: