replace \AtBeginDocument and \AtEndDocument in extra LaTeX code used in documents to be previewed#4322
Conversation
|
I think, this needs to be discussed in more details first. This can not happen with a general replacement, especially as classes tend to load relevant packages which are now disabled in preview. |
|
so it would me better to have a second option for this, which is not on by default (and maybe more things) |
|
Yes, i would leave the beamer part as is. However, are there any other cases than revtex which fail and need this ? |
|
I use only book, article or report. So I have no specific knowledge here and I can't remember any similar issue opened here in the past. Maybe @muzimuzhi has heard about it? Are there known issues or usage restrictions in the documentation of the packages added for preview? |
So the list of unsupported document classes would be long. Also it's hard to determine if a class supports format dumping, without checking its implementation. For example, if Related TeX-SX post(s)
If I remember correctly, XeLaTeX also doesn't support dumping OpenType fonts. |
|
@muzimuzhi Where comes dumping into place? I remember having issues when implementing preview for lualatex. The reason was that option Precompile Preamble (from Preview) was set and dumping (the result of the precompile) didn't work with tikz. But preview worked when the option was not set. Is it this you are talking about? |
3d6f186 to
7d5093e
Compare
|
thanks |
This PR resolves #4320. The problem described arises because the document class being used and TeXstudio’s PDF-preview both attempt to use the same LaTeX mechanism to achieve certain modifications, and in doing so they interfere with each other. They use the commands
\AtBeginDocumentand\AtEndDocumentto allow code to be specified in the document preamble that should be inserted at the beginning or end of the text written or selected for preview. The issue is resolved by having TeXstudio place the required modifications directly at the start and end of a temporary text used for preview, in exactly the same way these commands would.Description of the changes (line numbers from changed files):
buildmanager.cppbuilds up thedocumentenv. But here it's not clear if any changes should be added. This is well known intexstudio.cpp(l. 9432 and 9474). Thus we build necessary changes there and pass them as new parameters tobuildmanager.cpp(s.buildmanager.h). The code in l. 9474 in fact was the final chapter ofTexstudio::makePreviewHeaderwhich is moved toTexstudio::showPreview.Special behavior for Beamer class is not changed in any way.
Note: The discussion in comments below may appear somewhat outdated, as the description above has changed quite a lot (including PR's title).
Example of LaTeX document
Assume that the whole text line has been selected for preview.
Code finally compiled for **inline** preview
Code finally compiled for preview in embedded PDF-viewer