1

I am new to pythontex. I could run simple python code. However, I get error with slightly complex things.

The error I get is following:

This is PythonTeX 0.16

----  Messages for py:default:default  ----
* PythonTeX stderr - error on line 211:
    File "<outputdir>\py_default_default.py", line 62
      MW= 18e-3 u.kilogram/ u.mole
                ^
  SyntaxError: invalid syntax

--------------------------------------------------
PythonTeX:  notes - 1 error(s), 0 warning(s)

C:\texlive\2018\bin\win32\runscript.tlu:803: command failed with exit code 1:
python.exe c:\texlive\2018\texmf-dist\scripts\pythontex\pythontex.py notes.tex

Part of the code that has error is :

\begin{pycode}
import math
from pint import UnitRegistry
u = UnitRegistry()
alpha = 0.04
sigmaW = 72.86e-3 * u.newton / u.meter
mu    = 8.9e-4 * u.pascal * u.second
densityW = 1000 * u.kilogram / (u.meter ** 3)
densityIPA = 1000 * u.kilogram / (u.meter ** 3)
densityEtoh = 1000 * u.kilogram / (u.meter ** 3)
H = 1e-6 * u.meter
W = 28e-6 * u.meter
L= 32e-6 * u.meter
MW= 18e-3 u.kilogram/ u.mole
MIPA= 60.1e-3 u.kilogram/ u.mole
MEtoh= 46.07e-3 u.kilogram/ u.mole
R0=8.31446 u.joule / (u.mole * u.kelvin)
T0= 298 u.kelvin
N= 10
D0=2.4e-5 (u.meter ** 2)/(u.second)
C0=17.08e-3 u.kilogram/(u.meter ** 3)
tauevW=(densityW * N * R0 * T0 * (W **3))/(6* math.pi * D0 * C0 * sigmaW * MW)
\end{pycode}

Does anyone know how to solve this issue?

2
  • I'm no Python or pint expert, but while you had a * between number and unit in the first lines, you do not have that * in the last couple of lines. (Compare L= 32e-6 * u.meter and MW= 18e-3 u.kilogram/ u.mole) If I add a * everywhere I don't get an error with plain Python on the code.
    – moewe
    Sep 11, 2018 at 10:44
  • Could you please paste it ?
    – T.D.
    Sep 11, 2018 at 10:49

1 Answer 1

2

The issue is the lack of a multiplication sign between the number and units on line 62. Note that this omission is repeated on subsequent lines. The following has the operator added and executes without issue.

\begin{pycode}
import math
from pint import UnitRegistry
u = UnitRegistry()
alpha = 0.04
sigmaW = 72.86e-3 * u.newton / u.meter
mu    = 8.9e-4 * u.pascal * u.second
densityW = 1000 * u.kilogram / (u.meter ** 3)
densityIPA = 1000 * u.kilogram / (u.meter ** 3)
densityEtoh = 1000 * u.kilogram / (u.meter ** 3)
H = 1e-6 * u.meter
W = 28e-6 * u.meter
L = 32e-6 * u.meter
MW = 18e-3 * u.kilogram/ u.mole
MIPA = 60.1e-3 * u.kilogram/ u.mole
MEtoh = 46.07e-3 * u.kilogram/ u.mole
R0 = 8.31446 * u.joule / (u.mole * u.kelvin)
T0 = 298 * u.kelvin
N = 10
D0 = 2.4e-5 * (u.meter ** 2)/(u.second)
C0 = 17.08e-3 * u.kilogram/(u.meter ** 3)
tauevW = (densityW * N * R0 * T0 * (W **3))/(6* math.pi * D0 * C0 * sigmaW * MW)
\end{pycode}
6
  • I just copied and pasted above. Now I get following error: ---- Messages for py:default:default ---- * PythonTeX stderr - error on line 364: File "<outputdir>\py_default_default.py", line 140 import math ^ IndentationError: unexpected indent -------------------------------------------------- PythonTeX: notes - 1 error(s), 0 warning(s) C:\texlive\2018\bin\win32\runscript.tlu:803: command failed with exit code 1: python.exe c:\texlive\2018\texmf-dist\scripts\pythontex\pythontex.py notes.tex
    – T.D.
    Sep 11, 2018 at 10:54
  • @T.D. The new error you get seems to be about a different line (about 80 lines further down) not shown in the initial post. The issues seems to be a Python problem and not a LaTeX error. So maybe you should ask at stackoverflow.com
    – moewe
    Sep 11, 2018 at 11:00
  • The error is at "import math" ?
    – T.D.
    Sep 11, 2018 at 11:10
  • If I run following code. It runs properly. \documentclass[11pt]{article} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{pythontex} \begin{document} \LaTeX \begin{pycode} print ('Hello, \LaTeX') \end{pycode} %\newline \py{2+3} %\newline \end{document}
    – T.D.
    Sep 11, 2018 at 11:26
  • 1
    I am a bit dissapointed. There is no easy way to setup python in windows. I just reinstalled python and now even simple script is not working. Latex gives no error. Is there a way to know python is properly installed via Latex or CMD windows.
    – T.D.
    Sep 11, 2018 at 13:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .