0

I have some output from a CAS computation, in the form of a sequence of (sometimes gigantic) symbolic matrices. I simply want them displayed in a pdf (the CAS can output TeX), without having to coerce the individual matrices into the width of a preexisting document size.

Fitting each matrix into an equation environment and then decorating those with \resizebox{.9\hsize}{!} as suggested here works, but has undesirable results: the smaller matrices mushroom to gigantic font sizes, whereas the larger ones fit the page but are in tiny font.

What I'd rather do, if possible, is produce a document that automatically scales itself to the width of the widest equation. It was my understanding that the standalone document class is meant to achieve this (that was my reading of this post), but it doesn't do so for me.

In particular, the code

\documentclass[varwidth=true, border=0pt]{standalone}
\usepackage{amsmath}

\begin{document}

$
 \left(\begin{array}{rrrr}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & \frac{t_{3} t_{5} - t_{3}}{t_{5}} - \frac{{\left(t_{3} t_{5} - t_{3} - \frac{{\left(t_{3} t_{5} - t_{3}\right)} {\left(t_{5} - 1\right)}}{t_{5}}\right)} {\left(t_{3} t_{5} - t_{5}\right)}}{{\left(t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1\right)} t_{5}} & \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{{\left(t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1\right)} t_{5}^{2}} + \frac{1}{t_{5}} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{4} t_{5} - t_{4}\right)}}{{\left(t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1\right)} t_{4} t_{5}^{2}} & -\frac{t_{3} t_{5} - t_{5}}{{\left(t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1\right)} t_{4} t_{5}^{2}} \\
0 & \frac{t_{3} t_{5} - t_{3} - \frac{{\left(t_{3} t_{5} - t_{3}\right)} {\left(t_{5} - 1\right)}}{t_{5}}}{t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1} & -\frac{t_{5} - 1}{{\left(t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1\right)} t_{5}} + \frac{t_{4} t_{5} - t_{4}}{{\left(t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1\right)} t_{4} t_{5}} & \frac{1}{{\left(t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1\right)} t_{4} t_{5}}
\end{array}\right)  
$

\end{document}

(a snippet of my output) produces a cropped equation running off the right hand side of the pdf:

enter image description here


Edit:

After the helpful answers below I tried standalone on the full input available here. The result (with the maximum width, varwidth=16383.99999pt, as suggested in the comments) is

ERROR: Dimension too large.                                                                                            

--- TeX said ---
\height ->\ht \@tempboxa

l.2021 \end{document}

--- HELP ---                                                                                                           
From the .log file...

I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.

Since this is a new issue though, I have accepted the answer below by @Schrödinger's cat as resolving the original matter.

grobber
  • 181
  • Oh, it absolutely is not my intention to have different font sizes! I want some solution that detects how wide the pdf needs to be and makes it that wide. That's it, no font fiddling of any kind. – grobber Mar 08 '20 at 01:47
  • I see! Thanks for the clarification. –  Mar 08 '20 at 01:51
  • It seems to work if varwidth=true is removed, doesn't it? – frougon Mar 08 '20 at 01:57
  • It does work! The problem there though is that now it returns an error if I enclose the code in $$ of \[\] or \begin{equation*}\end{equation*} tags, as is my intention. I have many of these matrices (the document is 30+pages long, all looking like that), and I want the widest one to set the width. – grobber Mar 08 '20 at 02:08
  • Okay, thanks for the clarification. – frougon Mar 08 '20 at 08:29
  • Reorganize (e.g by defining auxilliary variables) your matrix. An equation that would render as more than a \textwidth worth just isn't readable. – vonbrand Mar 14 '20 at 00:32

2 Answers2

5

According to the standalone documentation you need only to increase the "cutoff" width to be rather large. If you use varwidth=16383.99999pt, then you hit the maximal dimension in Tex. If you want to create formulae that are more than 5.77 meters (!) wide, then this won't work.

\documentclass[varwidth=16383.99999pt, border=0pt]{standalone}
\usepackage{amsmath}

\begin{document}
$
 \left(\begin{array}{rrrr}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & \frac{t_{3} t_{5} - t_{3}}{t_{5}} - \frac{{\left(t_{3} t_{5} - t_{3} - \frac{{\left(t_{3} t_{5} - t_{3}\right)} {\left(t_{5} - 1\right)}}{t_{5}}\right)} {\left(t_{3} t_{5} - t_{5}\right)}}{{\left(t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1\right)} t_{5}} & \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{{\left(t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1\right)} t_{5}^{2}} + \frac{1}{t_{5}} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{4} t_{5} - t_{4}\right)}}{{\left(t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1\right)} t_{4} t_{5}^{2}} & -\frac{t_{3} t_{5} - t_{5}}{{\left(t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1\right)} t_{4} t_{5}^{2}} \\
0 & \frac{t_{3} t_{5} - t_{3} - \frac{{\left(t_{3} t_{5} - t_{3}\right)} {\left(t_{5} - 1\right)}}{t_{5}}}{t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1} & -\frac{t_{5} - 1}{{\left(t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1\right)} t_{5}} + \frac{t_{4} t_{5} - t_{4}}{{\left(t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1\right)} t_{4} t_{5}} & \frac{1}{{\left(t_{3} t_{5} - \frac{{\left(t_{3} t_{5} - t_{5}\right)} {\left(t_{5} - 1\right)}}{t_{5}} - t_{5} + 1\right)} t_{4} t_{5}}
\end{array}\right)  
$

\end{document}

enter image description here

  • Hmm.. Well, I don't know how large these will have to get, so my hope was I'd be able to have it resize itself automatically, for maximum portability. Setting a large width by hand in the preamble works fine with any other document class and the geometry packages paperwidth=<whatever> option too, for instance. This is a little better, but still requires some "manual" intervention. I might have to settle for it though. – grobber Mar 08 '20 at 02:12
  • even with that size, it errors out (ERROR: Dimension too large). I can do \documentclass{article} with the geometry package set to paperwidth=100cm for instance, but as I wrote above, that struck me as inelegant. It's looking like the only option at the moment though.. – grobber Mar 08 '20 at 02:17
  • @grobber No, I tried it out, there is no error. –  Mar 08 '20 at 02:18
  • @grobber You provide an MWE, and I post an answer based on that example. The answer does not produce an error. I cannot comment on codes that I do not know. –  Mar 08 '20 at 02:24
  • I have edited the original message to include a link to the full input I am interested in, and the error I receive from running with the maximum width. I apologize for not providing it in full before, but (a) it was unclear to me what the problem was to begin with, and (b) you'll see the input isn't exactly what passes for "minimal working". Indeed, I don't know what the minimal working example would be for this new error I'm encountering after making the changes you suggest (for which I thank you). In any case, it appears from the error that it's the height this is choking on. – grobber Mar 08 '20 at 02:41
2

Keeping the following lines in your full input:

\documentclass[11pt]{article}
\usepackage[paperwidth=200cm]{geometry}
\usepackage{amsmath}

I downloaded it and named it forum.tex and ran this line:

$ ltximg --extrenv equation -n -m 5 --prefix cas -o outfile forum.tex

generated the outfile.tex file with all equation* environments converted to .pdf images.

You will have to play a little with [scale=...], but you will no longer have the problem with fonts or ERROR: Dimension too large.

It is basically the same answer as @Schrödinger's cat but using a script, of course the input file must meet certain conditions (that everything is within equation for example) .

Good luck with this, I went through the same thing some time ago :)

  • Thanks! This is (essentially) the solution I'd settled on too: I've abandoned the standalone class, simply using article with an appropriately large paperwidth parameter passed to the geometry package. I think I'll script a wrapper around that, so I can pass that parameter (200, in the example you gave) as a command-line argument. – grobber Mar 08 '20 at 09:39