On 15/06/2015 6:18 a.m., Enrico Forestieri wrote:
On Sun, Jun 14, 2015 at 08:44:19PM +1200, aparsloe wrote:

With all the work done on preview for 2.2, I wonder if the following case
has been considered?

Open a document, myfile.lyx. Define a math macro using \jobname, e.g. so
that the source pane shows \global\long\def\test{\jobname}. Now in a math
inset write \test. In 2.1.3 this previews to something like
"lyxpreviewHE4348" (without quotes, in math italic), whereas, compiled to
pdf it is (the expected) "myfile" (without quotes, in math italic). The
preview is using the \jobname of the local latex run, which is unlikely to
be of interest, rather than the \jobname of the global latex run. This is
still the case, even if the macro is defined in the preamble.

I realise \jobname is highly unlikely to feature in math macros, but the
problem arises more generally in preview insets where it may well be a
natural command to use.
The preview machinery doesn't know the name of the document for which the
previews are being generated. I think this is a minor problem as only the
previews are affected and not the final result. However, if you really are
concerned about getting the same exact result also in the previews, you
can use the info-insert lfun and some ERT, as shown in the attached example.
It uses "info-insert buffer name" to obtain the name of the LyX document
and some latex (see the preamble) to transform name.lyx into name.tex.

Thank you Enrico. This is exactly what I've wanted to know for some time (and also provides an instance of getting preamble information into a preview that Kornel enquired about last year, 25/11/2014).

Yes, it is a minor problem as far as *previewing* goes, but that short-changes the preview machinery which might be thought of more as providing local latex runs. In my calculyx package wiki.lyx.org/Examples/Calculyx I use it to evaluate formulas, etc. Some of these calculations are slow and a number together would reduce document compilation to a crawl. But if the previews are "parked" in LyX notes or an inactive branch and the results of the calculations are saved to file, the results can then be loaded from file into the document proper without hindering speed of compilation. It is natural to use \jobname in the filename of the file to which results are saved.

Andrew

Reply via email to