pythontex icon indicating copy to clipboard operation
pythontex copied to clipboard

depythontex fails with Could not find command "py"

Open mfacorcoran opened this issue 3 years ago • 4 comments

I'm having an issue running depythontex on a file compiled with pythontex

the file is compiled using

\usepackage[depythontex=true]{pythontex}

but when I try to depythontex the tex file I get

% depythontex wr140_rxte_swift_nicer.tex

  • DePythonTeX error: Could not find command "py" on line 509

I'm using

% depythontex --version DePythonTeX 0.16

probably user error but I've tried to re-install and still getting the same error...

mfacorcoran avatar Jun 25 '21 14:06 mfacorcoran

Sometimes depythontex fails when a command is used inside of commands or environments that do something non-standard. This is largely a limitation of how LaTeX functions, but there are usually ways to work around it. Can you provide any information about what commands/environments are wrapping a \py command around line 509 of you document?

gpoore avatar Jun 25 '21 14:06 gpoore

Thanks for the quick reply Geoffrey  and the suggested  cause – this error does occur in a Table environment (actually the “deluxetable” environment of the aastex package).   

here’s the table.  Line 509 is the \enddata command

Thanks for the quick reply Geoffrey and the suggested cause – this error does occur in a Table environment (actually the “deluxetable” environment of the aastex package).

here’s the table. Line 509 is the \enddata command. I've defined various values (like eccen) in a pycode environment and am trying to display them in the table. The table does compile properly in pythontex btw

\begin{deluxetable}{lrl} \tabletypesize{\scriptsize} \tablecaption{Adopted Orbital and Stellar Parameters\label{tab:params}} \tablehead{\colhead{Parameter} & \colhead{Value} & \colhead{Reference or Comment}} \startdata Period (days) & \py{period.value}$\pm0.17$ & T21 (from Table 3, ``Adopted Fit'') \ eccentricity & \py{'{0:.4f}'.format(eccen)} $\pm$ \py{'{0:.4f}'.format(eccerr)}& T21 \ Time of Periastron Passage (MJD) & \py{'{0:.2f}'.format(t_tr.mjd)} $\pm$ \py{'{0:.2f}'.format(t_oerr)} & Best fit $T_{o}$ from T21 \ $\omega_{\mbox{WR}}$ (degrees) & \py{'{0:.2f}'.format(omega)} $\pm$ \py{'{0:.2f}'.format(omegerr)} & T21 \ $\Omega$ (degrees) & \py{'{0:.2f}'.format(Omega)} $\pm$ \py{'{0:.2f}'.format(Omegerr)} & T21 \ $i$ (degrees) & \py{'{0:.2f}'.format(inc)} & T21 \ $a$ (AU) & \py{'{0:.2f}'.format(sma.value)}$\pm$ \py{'{0:.2f}'.format(smaerr.value)} & T21 \ $M_{WR}$ (\msun) & \py{'{0:.2f}'.format(m1)} $\pm$ \py{'{0:.2f}'.format(m1err)} & T21 \ $M_{O}$ (\msun) & \py{'{0:.2f}'.format(m2)} $\pm$ \py{'{0:.2f}'.format(m2err)} & T21 \ $\dot{M}{WR}$ ($10^{-6}$\msun~yr$^{-1}$) & \py{'{0:.1f}'.format(Mdotwr/1e-6)} & \cite{2006MNRAS.372..801P} \ $\dot{M}{O}$ ($10^{-6}$\msun~yr$^{-1}$) & \py{'{0:.1f}'.format(Mdoto/1e-6)} & \cite{2006MNRAS.372..801P} \ $V_{\infty, WR}$ (km~s$^{-1}$) & \py{f'{Vwr:.0f}'} &\cite{2001aap...376..460S} \ $V_{\infty, O}$ (km~s$^{-1}$) & \py{f'{Vo:.0f}'} & \cite{2001aap...376..460S} \ $\eta$ & \py{'{0:.2f}'.format((4.30e-52860)/(8.e-73100))} & $=(\dot{M}{WR}V{\infty, WR}$)/($\dot{M}{O}V{\infty, O}$)\ Adiabatic-Shock Opening Angle (degrees)\tablenotemark{a} & 41.3 & \cite{2009ApJ...703...89G} equation (11) \ Radiative-Shock Opening Angle (degrees)\tablenotemark{a} & 31.7 & \cite{1996ApJ...469..729C} equation (28) \ WR-Shock Stand-off Distance\tablenotemark{b} & 0.876 & \cite{1996ApJ...469..729C} equation (27) \ Distance (pc) & \py{'{0:.0f}'.format((D.to(u.pc)).value)} & Gaia~DR2 & T21 \ $v$ & $7.07$ & \cite{1984ApJ...281..789M} \ $b-v$ & $+0.27$ & \cite{1984ApJ...281..789M} \ $N_{H}$ ($10^{21}$~cm$^{-2})$ & 4.3 & Interstellar absorption column density \enddata \tablenotetext{a}{Theoretical asymptotic opening half-angle determined by $\eta$} \tablenotetext{b}{Fraction of binary separation determined by $\eta$} \end{deluxetable}

mfacorcoran avatar Jun 25 '21 14:06 mfacorcoran

My guess is that deluxetable is doing some special processing that throws off the line numbering that depythontex expects. You might try switching from the \py command to the pysub environment, which should be able to work around this. Currently, deluxetable processes everything first, and then PythonTeX gets the \py commands. This works for normal PythonTeX functionality but not the additional requirements of depythontex. By switching to pysub, PythonTeX will receive everything before deluxetable and can process things first in a way that works with depythontex while maintaining LaTeX functionality.

To use pysub, wrap the entire deluxetable in \begin{pysub}...\end{pysub} and then replace each \py with !. Something like this, similar to a Python format string but using !{...} for substitution fields:

\begin{pysub}
\begin{deluxetable}{lrl}
\tabletypesize{\scriptsize}
\tablecaption{Adopted Orbital and Stellar Parameters\label{tab:params}}
\tablehead{\colhead{Parameter} & \colhead{Value} & \colhead{Reference or Comment}}
\startdata
Period (days)  &      !{period.value}$\pm0.17$  & T21   (from Table 3,  ``Adopted Fit'') \\
eccentricity  &     !{'{0:.4f}'.format(eccen)} $\pm$   !{'{0:.4f}'.format(eccerr)}& T21   \\
Time of Periastron Passage (MJD) &   !{'{0:.2f}'.format(t_tr.mjd)} $\pm$  !{'{0:.2f}'.format(t_oerr)}   & Best fit $T_{o}$ from T21     \\
$\omega_{\mbox{WR}}$ (degrees) &     !{'{0:.2f}'.format(omega)} $\pm$ !{'{0:.2f}'.format(omegerr)}  & T21     \\
$\Omega$ (degrees)  &   !{'{0:.2f}'.format(Omega)}   $\pm$ !{'{0:.2f}'.format(Omegerr)} & T21   \\
$i$ (degrees)  &   !{'{0:.2f}'.format(inc)}  & T21    \\
$a$ (AU) & !{'{0:.2f}'.format(sma.value)}$\pm$  !{'{0:.2f}'.format(smaerr.value)} & T21 \\
$M_{WR}$ (\msun)   &     !{'{0:.2f}'.format(m1)} $\pm$    !{'{0:.2f}'.format(m1err)} & T21   \\
$M_{O}$ (\msun)  &      !{'{0:.2f}'.format(m2)}  $\pm$    !{'{0:.2f}'.format(m2err)} & T21   \\
$\dot{M}_{WR}$ ($10^{-6}$\msun~yr$^{-1}$) &  !{'{0:.1f}'.format(Mdotwr/1e-6)}  & \cite{2006MNRAS.372..801P} \\
$\dot{M}_{O}$ ($10^{-6}$\msun~yr$^{-1}$) &  !{'{0:.1f}'.format(Mdoto/1e-6)}  &  \cite{2006MNRAS.372..801P} \\
$V_{\infty, WR}$ (km~s$^{-1}$) & !{f'{Vwr:.0f}'}  &\cite{2001aap...376..460S} \\
$V_{\infty, O}$ (km~s$^{-1}$) &  !{f'{Vo:.0f}'}  & \cite{2001aap...376..460S} \\
$\eta$ & !{'{0:.2f}'.format((4.30e-5*2860)/(8.e-7*3100))} & $=(\dot{M}_{WR}V_{\infty, WR}$)/($\dot{M}_{O}V_{\infty, O}$)\\
Adiabatic-Shock Opening Angle (degrees)\tablenotemark{a} & 41.3 &  \cite{2009ApJ...703...89G} equation (11) \\
Radiative-Shock Opening Angle (degrees)\tablenotemark{a} & 31.7 & \cite{1996ApJ...469..729C} equation (28) \\
WR-Shock Stand-off Distance\tablenotemark{b} & 0.876 & \cite{1996ApJ...469..729C} equation (27) \\
Distance (pc)  &   !{'{0:.0f}'.format((D.to(u.pc)).value)}  & Gaia~DR2 \& T21 \\
$v$ & $7.07$ & \cite{1984ApJ...281..789M} \\
$b-v$ & $+0.27$ & \cite{1984ApJ...281..789M} \\
$N_{H}$ ($10^{21}$~cm$^{-2})$ & 4.3 & Interstellar absorption column density
\enddata
\tablenotetext{a}{Theoretical asymptotic opening half-angle determined by $\eta$}
\tablenotetext{b}{Fraction of binary separation determined by $\eta$}
\end{deluxetable}
\end{pysub}

gpoore avatar Jun 25 '21 15:06 gpoore

Thanks for all the help Geoffrey. I evaluated the \py{} code by hand and replaced the code with the evaluated values which solved the deluxetable problem (there was another issue with a \py{} in a caption environment) and allowed me to depythontex without problem. I'll try the \pysub solution you proposed though and let you know how that works.

Update - the \pysub solution works to solve the deluxtable environment issue

mfacorcoran avatar Jun 25 '21 17:06 mfacorcoran