texstudio-org / texstudio

TeXstudio is a fully featured LaTeX editor. Our goal is to make writing LaTeX documents as easy and comfortable as possible.
http://www.texstudio.org/
GNU General Public License v3.0
2.75k stars 342 forks source link

Show inline preview using original preamble only #3166

Closed octaeder closed 1 year ago

octaeder commented 1 year ago

Describe the feature and the current behavior/state

Compiling the document with the complete include tree has many advantages: Layout is exactly as expected, you have full access to the contents and the index, no problems with missing references. An obvious disadvantage is that this method can be quite time consuming especially when multiple runs are necessary. Cutting down the include three may speed up things but all the advantages have gone.

But txs offers a great preview functionality. Unfortunately the result is often not similar to what you get from a full compile. This happens because the preview compile adds some extra code at the end of the original preamble (s. texstudio.cpp):

\usepackage[active,tightpage]{preview}
\usepackage{varwidth}
\AtBeginDocument{\begin{preview}\begin{varwidth}{\linewidth}}
\AtEndDocument{\end{varwidth}\end{preview}}

This optimizes the output, which is quite nice particularly for tooltips. But the inline preview will not be what one will get from the final compile, since \parindent is changed (anything else?). But I often need to check if the text layout is fine in each line: Spacing between words, text fits in the line so nothing is moved into the right margin, and I want to avoid line breaks within inline formulae. Fine tuning the document in this way is very time consuming, thus a preview option that gives you a preview similar to the final document would be of great help. In fact this is available when you set Preview Display Mode to Show in embedded viewer. But in this way you can't compare the new result to the old one.

Who will benefit with this feature?

Almost anyone want's to avoid the time consuming work of adjusting text. Therefore a preview with original preamble should be of great help.

Any Other info

Current behavior; grafik

Expected behavior: grafik

Derived from (build with lualatex):

\documentclass[ngerman,10pt,a5paper]{article}
\usepackage[T1]{fontenc}
\usepackage[width=11cm, height=17cm]{geometry}
\usepackage{mathtools}
\usepackage{babel}
\begin{document}
Lorem ipsumdolor sitamet, consetetur sadipscing elitrsed diamnonumy eirmod
tempor invidunt utore etadolor magna ali $\forall (a,b,c,d,e,f,g,\ldots,z)$
erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren
\end{document}
octaeder commented 1 year ago

@sunderme please comment following state of development:

New standard (not advanced) option with tooltip, checked by default (i.e. old behavior):

grafik (click image to enlarge)

Also quick access via menu (Alt+I, S):

grafik

Compare old vs. new inline preview (be aware of differences in word spacing, line breaks, and footnote marks). To toggle between the two results use Alt+I, S, Alt+P:

grafik (click image to enlarge)

That works analogously when Preview Display Mode is set to Preview Panel. When you choose Tooltip as Preview Display Mode:

grafik (click image to enlarge)

The option has no effect when Preview Display Mode is set to Show in embedded viewer, or on math tooltips:

grafik

Slightly changed code to:

\documentclass[ngerman,10pt,a6paper]{article}
\usepackage[T1]{fontenc}
\usepackage[width=7cm, height=10cm]{geometry}
\usepackage{mathtools}
\usepackage{babel}
\begin{document}
Lorem ipsumdolor sitamet, consetetur sadipscing elitrsed diamnonumy eirmod
tempor invidunt utore etadolor magna ali $\forall (a,b,c,d,e,f,g,\ldots,z)$
erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren\footnote{ae öds edod}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren
\end{document}
sunderme commented 1 year ago

the inline preview is definitely not intended to contain whole pages. Hence "shrink page" is not really meaningful, especially as it contradicts the first idea, to achieve results like a full compile. The inline preview is for formulas and the like and there the current solution works as intended.

octaeder commented 1 year ago

"shrink page" means the old behavior, and that is definitely shrinking the page and the minipage. Since it's the default, it will work as you expect it and and as it is "intended".

But what you think is intended doesn't always happen. Out of the box choose Preview with dvips/ghostscript and you will see exactly what I developed here for pdf. Seems that these manipulations in the preamble would not work with dvips. But I would not recommend removing option Preview with dvips/ghostscript, because it may be usefull for someone.

Of course, the main target is not to preview whole pages. But it guarantees that preview works as well as possible not only for formulas. And you can still choose where to see it, it doesn't have to be inline. So anyone who has to cope with overfull boxes/lines (and I believe there are many people doing so) can quickly analyze effects of changing the LaTeX code at some point without waiting for large compiles. But this is not possible when you use a minipage. Looking at formulas is not the end. With this new option the value of txs really increases. So why stick with limited functionality?

sunderme commented 1 year ago

I don't like to have two modes here. It basically means that you are "always" in the wrong mode. Looking at compilation result, especially for the actual text typesetting, is exactly what the embedded viewer is for. If your compile times get too long, maybe take a look at \includeonly or subfiles. Last option may be using macro for special compilations.

octaeder commented 1 year ago

As said using preview in embedded viewer is not suitable for cases described above. I give more arguments: Even when you open a second pdf viewer window then you will simply see your document twice. Now running the preview will replace the document by the preview in both viewers. You may argue that Ctrl+click will at least bring back the original document. But there is another problem you may not have thought of: Moving over the editor may start previews and your main document will be missing again. That leads to nothing useful because txs is not made for previewing two different documents. I also mentioned why cutting down the document is not the best way for working. So I have given a whole bunch of arguments that speak for doing the change. Even so you don't want to accept it because one could "always" be in the wrong mode what can be fixed with three key strokes that toggle mode and update preview. Maybe all those should simply stay with the default, i.e. nothing changes.

octaeder commented 1 year ago

Final words can be found in PR #3175 that has been closed without merging.

octaeder commented 1 year ago

@sunderme What about this?

grafik

This can be achieved by simply adding some latex code (no other changes, no need for options) in makePreviewHeader as follows:

header << "\usepackage[active,tightpage]{preview}" << "\usepackage{varwidth}" << "\AtBeginDocument{\newlength{\txsParindent}\setlength{\txsParindent}{\parindent}\begin{preview}\begin{varwidth}{\linewidth}\setlength{\parindent}{\txsParindent}}" << "\AtEndDocument{\end{varwidth}\end{preview}}";

This sets parindent correct, but will not show, that the formula protrudes the margin. But parindent is the more important one.

octaeder commented 1 year ago

with env varwidth this doesn't really help. We would need to replace it by minipage.