pythontex icon indicating copy to clipboard operation
pythontex copied to clipboard

PythonTeX stderr - pyconcode problems.

Open reckoner opened this issue 9 years ago • 11 comments

I get this error a lot. There's nothing wrong with the pyconcode. It has things like plot() in it which produces some output that I do not use. Is there a way to make this a warning instead of an error?

* PythonTeX stderr - error near line 703 in console code:
    Console code is not typeset, and should have no output

BTW, this is about PythonTeX v0.12 on Ubuntu.

Thanks!

reckoner avatar Mar 03 '15 16:03 reckoner

When I created pyconcode, I wanted to make sure that any code that produced output wasn't accidentally overlooked. But I wasn't thinking about cases like plot(), which produce ignorable output. I will try figure out a more flexible way to deal with this in the future. Maybe one mode that lets you do whatever you want, and another that gives warnings whenever something might be wrong. I'm getting ready to overhaul the console system to add several new features, and will add this to the list.

gpoore avatar Mar 03 '15 17:03 gpoore

Okay. That's good news. I will track the status of this issue for updates.

reckoner avatar Mar 04 '15 00:03 reckoner

Additionally, in the pyconsole environment, there is sometimes lots of output generated by plot commands. I realize there is a separate pylab environment, but sometimes I like to discuss a computation and then illustrate how it can be plotted within the same family. Right now, the only workaround is to assign dummy outputs to plot as in _=plot( in order to get the corresponding output suppressed.

Thanks!

reckoner avatar Mar 06 '15 18:03 reckoner

If you can give me a short example document that illustrates the sort of output you'd like to suppress, I can look into that when I'm making the other modifications.

gpoore avatar Mar 06 '15 18:03 gpoore

see below.

Thanks!


%%
%% Automatically generated file from DocOnce source
%% (https://github.com/hplgit/doconce/)
%%


%-------------------- begin preamble ----------------------

\documentclass[%
twoside,                 % oneside: electronic viewing, twoside: printing
final,                   % or draft (marks overfull hboxes, figures with paths)
10pt]{article}

\listfiles               % print all files needed to compile this document

\usepackage{relsize,epsfig,makeidx,color,setspace,amsmath,amsfonts}
\usepackage[table]{xcolor}
\usepackage{bm,microtype}

\usepackage{fancyvrb} % packages needed for verbatim environments

\usepackage[T1]{fontenc}
%\usepackage[latin1]{inputenc}
\usepackage[utf8]{inputenc}

\usepackage{lmodern}         % Latin Modern fonts derived from Computer Modern

% Hyperlinks in PDF:
\definecolor{linkcolor}{rgb}{0,0,0.4}
\usepackage[%
    colorlinks=true,
    linkcolor=black,
    urlcolor=black,
    citecolor=black,
    filecolor=black,
    %filecolor=blue,
    pdfmenubar=true,
    pdftoolbar=true,
    bookmarksdepth=3   % Uncomment (and tweak) for PDF bookmarks with more levels than the TOC
            ]{hyperref}
%\hyperbaseurl{}   % hyperlinks are relative to this root

\setcounter{tocdepth}{2}  % number chapter, section, subsection

% Tricks for having figures close to where they are defined:
% 1. define less restrictive rules for where to put figures
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{2}
\setcounter{totalnumber}{4}
\renewcommand{\topfraction}{0.85}
\renewcommand{\bottomfraction}{0.85}
\renewcommand{\textfraction}{0.15}
\renewcommand{\floatpagefraction}{0.7}
% 2. ensure all figures are flushed before next section
\usepackage[section]{placeins}
% 3. enable begin{figure}[H] (often leads to ugly pagebreaks)
%\usepackage{float}\restylefloat{figure}

% prevent orhpans and widows
\clubpenalty = 10000
\widowpenalty = 10000

% --- end of standard preamble for documents ---

\usepackage{booktabs}
\usepackage[autoprint=true]{pythontex}

% insert custom LaTeX commands...

\raggedbottom
\makeindex

%-------------------- end preamble ----------------------

\begin{document}


\input{newcommands_keep}

% ------------------- main content ----------------------



% ----------------- title -------------------------

\thispagestyle{empty}

\begin{center}
{\LARGE\bf
\begin{spacing}{1.25}
test this
\end{spacing}
}
\end{center}

% ----------------- author(s) -------------------------

\begin{center}
{\bf me${}^{}$} \\ [0mm]
\end{center}

    \begin{center}
% List of all institutions:
\end{center}

% ----------------- end author(s) -------------------------

\begin{center}
Mar 9, 2015
\end{center}

\vspace{1cm}


You can create the array as in the following,

\begin{pyconsole}[][fontsize=\footnotesize]
import numpy as np
x = np.arange(30)
print x
\end{pyconsole}

\noindent and you can plot it here.

\begin{pyconsole}[][fontsize=\footnotesize]
from matplotlib.pylab import subplots
fig,ax= subplots()
ax.plot(x,x,'-o')
fig.savefig('../demo.png')
\end{pyconsole}



\begin{figure}[ht]
  \centerline{\includegraphics[width=0.8\linewidth]{demo.png}}
  \caption{
  demo plot \label{fig:learning_theory_tmp_001}
  }
\end{figure}
%\clearpage % flush figures fig:learning_theory_tmp_001


\noindent Wasn't that easy! It would be nice to supress the output of the above \Verb!ax.plot!, especially when
the plot could be complicated with multiple unused outputs.

% ------------------- end of main content ---------------


\printindex

\end{document}

image

reckoner avatar Mar 09 '15 15:03 reckoner

But this is how the python console works.

I understand your objection, but why not show the code without the >>> for every line? (i.e. without using the 'pyconsole" environment). In addition, the output can be suppressed by lines=ax.plot(...).

On 09 Mar 2015, at 16:11, reckoner [email protected] wrote:

see below.

Thanks!

%% %% Automatically generated file from DocOnce source %% (https://github.com/hplgit/doconce/) %%

%-------------------- begin preamble ----------------------

\documentclass[% twoside, % oneside: electronic viewing, twoside: printing final, % or draft (marks overfull hboxes, figures with paths) 10pt]{article}

\listfiles % print all files needed to compile this document

\usepackage{relsize,epsfig,makeidx,color,setspace,amsmath,amsfonts} \usepackage[table]{xcolor} \usepackage{bm,microtype}

\usepackage{fancyvrb} % packages needed for verbatim environments

\usepackage[T1]{fontenc} %\usepackage[latin1]{inputenc} \usepackage[utf8]{inputenc}

\usepackage{lmodern} % Latin Modern fonts derived from Computer Modern

% Hyperlinks in PDF: \definecolor{linkcolor}{rgb}{0,0,0.4} \usepackage[% colorlinks=true, linkcolor=black, urlcolor=black, citecolor=black, filecolor=black, %filecolor=blue, pdfmenubar=true, pdftoolbar=true, bookmarksdepth=3 % Uncomment (and tweak) for PDF bookmarks with more levels than the TOC ]{hyperref} %\hyperbaseurl{} % hyperlinks are relative to this root

\setcounter{tocdepth}{2} % number chapter, section, subsection

% Tricks for having figures close to where they are defined: % 1. define less restrictive rules for where to put figures \setcounter{topnumber}{2} \setcounter{bottomnumber}{2} \setcounter{totalnumber}{4} \renewcommand{\topfraction}{0.85} \renewcommand{\bottomfraction}{0.85} \renewcommand{\textfraction}{0.15} \renewcommand{\floatpagefraction}{0.7} % 2. ensure all figures are flushed before next section \usepackage[section]{placeins} % 3. enable begin{figure}[H](often leads to ugly pagebreaks) %\usepackage{float}\restylefloat{figure}

% prevent orhpans and widows \clubpenalty = 10000 \widowpenalty = 10000

% --- end of standard preamble for documents ---

\usepackage{booktabs} \usepackage[autoprint=true]{pythontex}

% insert custom LaTeX commands...

\raggedbottom \makeindex

%-------------------- end preamble ----------------------

\begin{document}

\input{newcommands_keep}

% ------------------- main content ----------------------

% ----------------- title -------------------------

\thispagestyle{empty}

\begin{center} {\LARGE\bf \begin{spacing}{1.25} test this \end{spacing} } \end{center}

% ----------------- author(s) -------------------------

\begin{center} {\bf me${}^{}$} \ [0mm] \end{center}

\begin{center}

% List of all institutions: \end{center}

% ----------------- end author(s) -------------------------

\begin{center} Mar 9, 2015 \end{center}

\vspace{1cm}

You can create the array as in the following,

\begin{pyconsole}[][fontsize=\footnotesize] import numpy as np x = np.arange(30) print x \end{pyconsole}

\noindent and you can plot it here.

\begin{pyconsole}[][fontsize=\footnotesize] from matplotlib.pylab import subplots fig,ax= subplots() ax.plot(x,x,'-o') fig.savefig('../demo.png') \end{pyconsole}

\begin{figure}[ht] \centerline{\includegraphics[width=0.8\linewidth]{demo.png}} \caption{ demo plot \label{fig:learning_theory_tmp_001} } \end{figure} %\clearpage % flush figures fig:learning_theory_tmp_001

\noindent Wasn't that easy! It would be nice to supress the output of the above \Verb!ax.plot!, especially when the plot could be complicated with multiple unused outputs.

% ------------------- end of main content ---------------

\printindex

\end{document}

� Reply to this email directly or view it on GitHub.

obtitus avatar Mar 09 '15 15:03 obtitus

Stylistically, I try to use the >>> prefix to emphasize that this is something the student can type into the console and reproduce the purported output. Not using the >>> is meant to emphasized codes that are meant to be imported or used from a module, not necessarily reproduced by typing into the console. This gives me the option of talking about how code should be structured in a file, thereby meant to be imported by others, and code that is meant to use material in separate files, at the console.

This is mainly a stylistic issue. I understand it is outside of your usage pattern.

reckoner avatar Mar 09 '15 16:03 reckoner

@reckoner The solution I am considering for #55 will probably give you what you want for this case as well. It should be possible to execute code within the console emulator, but typeset either the console output (what you get currently) or the raw code. Basically, acts like pyblock in terms of what is typeset, acts like pyconsole in terms of execution.

gpoore avatar Mar 09 '15 16:03 gpoore

I do understand, I just want to be a bit difficult ;) The main reason for being difficult is that I am not convinced this is a usage pattern that pythontex should support, at least directly.

A possible solution is to have a pyblock where a (fancyvrb setting?) can put >>> on the start of every line. My main objective is to seperate how code is executed from how it is being displayed.

Would it then not be confusing for the students to observe a different behavior in their python console, i.e. would you then not get questions of what all the [<matplotlib.lines.Lines2D ...] is all about?

On 09 Mar 2015, at 17:22, reckoner [email protected] wrote:

Stylistically, I try to use the >>> prefix to emphasize that this is something the student can type into the console and reproduce the purported output. Not using the >>> is meant to emphasized codes that are meant to be imported or used from a module, not necessarily reproduced by typing into the console. This gives me the option of talking about how code should be structured in a file, thereby meant to be imported by others, and code that is meant to use material in separate files, at the console.

This is mainly a stylistic issue. I understand it is outside of your usage pattern.

� Reply to this email directly or view it on GitHub.

obtitus avatar Mar 09 '15 16:03 obtitus

@obtitus

Excellent point which brings us to the heart of the issue. In the case where there is only one plot, it is no big deal to leave in the [<matplotlib.lines.Lines2D ...]. This is not confusing for students. However, I wanted to put more complicated plots in the corresponding pyconcode block so that the figure would be created and referenced in the source document while sharing the same namespace as the typeset pyconsole block. In the case where the pyconsole produces output, PythonTeX throws an error unless the outputs are captured in dummy variables. It is no big deal to put dummy variables in there to stop this error, nonetheless.

What I'm trying to get at is sometimes there is code meant to be typed by the student at the console that should produce a complicated figure, but sometimes that figure needs to be heavily formatted in order to be included into the LaTeX source document. Doing this formatting generates a lot of superfluous outputs (e.g. ax.axis()) that would be distracting to put in pyconsole and that I would like to relegate to pyconcode in a clean way.

I hope that helps.

reckoner avatar Mar 09 '15 16:03 reckoner

Yes. So since switching between console and non console is technically difficult to implement, I would rather look for a way to add the >>> to a standard code environment. You can the switch between pyblock and pycode for the code you want shown and code you want to keep hidden.

Related: by using autoprint=false you have much better control over what is included in the latex document.

On 09 Mar 2015, at 17:46, reckoner [email protected] wrote:

@obtitus

Excellent point which brings us to the heart of the issue. In the case where there is only one plot, it is no big deal to leave in the [<matplotlib.lines.Lines2D ...]. This is not confusing for students. However, I wanted to put more complicated plots in the corresponding pyconcode block so that the figure would be created and referenced in the source document while sharing the same namespace as the typeset pyconsole block. In the case where the pyconsole produces output, PythonTeX throws an error unless the outputs are captured in dummy variables. It is no big deal to put dummy variables in there to stop this error, nonetheless.

What I'm trying to get at is sometimes there is code meant to be typed by the student at the console that should produce a complicated figure, but sometimes that figure needs to be heavily formatted in order to be included into the LaTeX source document. Doing this formatting generates a lot of superfluous outputs (e.g. ax.axis()) that would be distracting to put in pyconsole and that I would like to relegate to pyconcode in a clean way.

I hope that helps.

� Reply to this email directly or view it on GitHub.

obtitus avatar Mar 09 '15 16:03 obtitus