Ask Your Question
0

LaTeX Output: How to replace Brackets and add Dollars

asked 2020-01-04 08:58:53 -0500

geroyx gravatar image

updated 2020-01-04 11:17:54 -0500

FrédéricC gravatar image

I have

x = 1
data = [x/n for n in range (1,4)]
M = latex(data)

print M
print M.replace('\left[', '$').replace(', ', '$, ').replace('\right]', '$')

Out Actual:

\left[1, \frac{1}{2}, $\frac{1}{3}$ \right]
$1$, \frac{1}{2}, $\frac{1}{3}$\right]

But I need:

Out Target:

$1$, $\frac{1}{2}$, $\frac{1}{3}$
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2020-01-04 10:23:58 -0500

dsejas gravatar image

Hello, @geroyx! Try the following:

x = 1
data = [x/n for n in range (1,4)]

M = []
for d in data:
    M.append('$' + latex(d).replace(' ','') + '$')
print(', '.join(M))

The result should be

$1$, $\frac{1}{2}$, $\frac{1}{3}$
edit flag offensive delete link more

Comments

This works, thx.

geroyx gravatar imagegeroyx ( 2020-01-04 11:16:12 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-01-04 08:58:53 -0500

Seen: 46 times

Last updated: Jan 04