Dear all, I've been using Sage to try to display some graphical formulas, containing sums of pictures of graphs multiped by coefficients. The idea is to have something looking like the attached picture.
My idea for achieving this was to create a set of symbolic variables, one per graph, with the value latex_name set to some LaTeX code for drawing the graph (I already have code for generating the LaTeX from a given graph). Along the way I came across a few peculiarities which I haven't seen documented anywhere... [ all of these tested using 'SageMath version 8.0, Release Date: 2017-07-21'. Once built I will check against the latest version in git. ] - Creating variables with newlines in their LaTeX name. This works as one might expect normally, but it seems to break down when displaying sums: sage: test_var = SR.var('test_var', latex_name='\\text{Lorem}\n\\text{Ipsum dolor}') sage: latex(test_var) {\text{Lorem} \text{Ipsum dolor}} sage: latex(3*test_var) 3 \, {\text{Lorem} \text{Ipsum dolor}} sage: latex(test_var+3) {\text{Lorem} + 3 Understandably, trying to display this last equation using view() generates an error. - Using the tightpage option. If one tries to include a pgfpicture inside the latex_name, then the tightpage option (which defaults to True) doesn't work: sage: latex.add_package_to_preamble_if_available('pgf') sage: test_var = SR.var('test_var', latex_name=r'\begin{pgfpicture} \pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{1in}{1in}} \pgfusepath{stroke} \end{pgfpicture}') sage: latex(test_var) sage: view(test_var) <tries to open an empty PDF document> sage: view(test_var, tightpage=False) <displays the picture on a full-sized page> The cause of this seems to be the way that the tightpage module is used. The code in view() adds in '\PreviewEnvironment{page}' to the preamble, and sets the left and right math delimeters as '\begin{page}$' and '$\end{page}' respectively. However, in _latex_file (called by view), maths delimeters are not added when the string '\begin{pgfpicture}' appears. This could be remedied by perhaps having another pair of arguments to _latex_file called item_left and item_right, which are prepended and appended as needed. This leads on to: - Expressions involving numbers and pictures don't produce valid LaTeX code. Extending the above code example to the following causes a LaTeX error: sage: latex.add_package_to_preamble_if_available('pgf') sage: test_var = SR.var('test_var', latex_name=r'\begin{pgfpicture} \pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{1in}{1in}} \pgfusepath{stroke} \end{pgfpicture}') sage: latex(test_var) sage: view(3/2 * test_var, tightpage=False) <causes a LaTeX error> As above, this is because maths delimiters are not added before and after the string, so the generated LaTeX, containing \frac{3}{2}, fails to compile. I can't think of an obvious solution other than the fact that pgfpicture should work perfectly well within a maths environment, so it may as well be added anyway. I have looked on these mailing list and on Ask sage and I haven't found anything about these behaviours; I apologise if this is a duplicate of some post elsewhere. Best wishes, Peter Banks -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.