Ask Your Question
0

LaTeX Output: How to replace Brackets and add Dollars

asked 2020-01-04 15:58:53 +0100

geroyx gravatar image

updated 2020-01-04 18:17:54 +0100

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 17:23:58 +0100

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 18:16:12 +0100 )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 15:58:53 +0100

Seen: 215 times

Last updated: Jan 04 '20