'How to create an image of LaTeX output with borders using Sympy 'preview' function

I'm trying to save the text in TeX format as a picture sized to fit the content. As I understand it, the Preview function allows you to configure additional parameters of the output document. But I can't seem to set any indents from the picture borders on all sides. I tried using a 'standalone' document class with 'border' attribute, but that doesn't work (check the code).
I'm using MiKTeX, Python 3.10 and PyCharm.

Code:

import sympy
preamble = "\\documentclass[border={1cm 1cm 1cm 1cm},varwidth=true]{standalone}\n\\begin{document}"
text = r"lala\\lalala"
sympy.preview(f'${text}$', viewer="file", preamble=preamble, filename="output.png", dvioptions=['-D', '600'])

What I get: result without borders

What I expect to see: expected result with borders

Question: What is the correct way to create indentation on all sides of an image?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source