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?

  • 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 '18 at 10:44
  • Could you please paste it ? – T.D. Sep 11 '18 at 10:49
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}
  • 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 '18 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 '18 at 11:00
  • The error is at "import math" ? – T.D. Sep 11 '18 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 '18 at 11:26
  • @T.D. Well, the error says “Unexpected indent”, so make sure you aren’t indenting the import math (and also everything after) line, since indentation has meaning in python. – Troy Sep 11 '18 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.