Remove support for python 1.x (really)
This code has not been used for a long time, probably never, since some code
above requires at least python 2.4 to work.
I got to this code by running futurize from python-future. There are no
significant warnings, mostly are related with the division but since
we are dividing floats there is no change between python 2 and 3.
python 2 does not allow to declare a string as raw byte so we double
the backslashes and remove the r preffix
python 3 accepts rb"..." meaning a byte string that is raw. In this context
raw means that the backslash does not has any special meaning and thus it
is not escaped. This is usefull together with regular expressions where the
backslashes are special.
In the worst possible case, like this one, we must use 4 backslashes to represent
one in the regular expression...
Instead of redefining \usepackage for avoiding the microtype package
when generating previews in dvi mode, the draft option can be used
for disabling it. This also allows to somewhat simplify the
fix_latex_file function.
The strategy adopted in bc47054b had some drawbacks related to the way
instant preview snippets are generated. See the subthread starting at
http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg187916.html
for details.
The strategy adopted in this commit is that of adding macro definitions
only for the macros actually used in a preview snippet, independently
of whether some macro was already used in a previous snippet. In this way
the snippets don't need to be changed according to whether they are
compiled as a whole or separately from each other. This fact was causing
the regeneration of a preview snippet whenever the cursor entered the
corresponding inset, even if the generated image would have not changed.
The problem of defining or redefining a macro is taken care by the
python scripts.
* Provide for vector fonts only if needed.
* Make sure microtype doesn't throw a trantum in dvi mode.
* Use correct macro definition in preview insets.
Avoid that \newcommand[x] definitions of math macros are pushed multiple
times to the preview loader.
Redefinitions (via \renewcommand[x]) are properly handled.
If use of hyperref is detected, the postscript route is not attempted
(because we know it will fail) and the PDF route is directly chosen.
Also account for all upper case extensions for pdflatex image files.
Was forgetting this last bit from 64e0c558. Also give a message such
that the user is informed that not everything is lost if latex fails.
With this, the previews are generated also when the document directly
specifies a specific pdf output format.
This is a followup commit to 691fdea3 and restores the behavior of the
script as it was intended before 64e0c558, other than taking into account
possible inclusion of files that only pdflatex can process and the
possibility of multiple defined math macros.
The instant previews in the math manual now work again.
When the dvipng route is selected and latex fails, the lyxpreview2bitmap.py
script simply bails out. The failure may be due to using a specific pdf
only feature in ERT (for example, the inclusion of a pdf image).
In this case the procedure may succeed simply trying to use pdflatex
and the legacy conversion method.
Fedora ships these chmod 644 and has never seen a problem. The advantage
to doing this is that it better controls what version of python we are
using to launch the script, and it will reveal if we're somehow somewhere
not controlling that properly.
Let's have this in trunk for testing. The real difference maker
when it comes to color is whether we use dvipng or ghostscript.
For dvipng:
- The color info is passed as command-line arguments.
- The tightpage option is not necessary, and since it adds
ps specials to the output, we shouldn't use it.
For ghostscript:
- The color info needs to be in the latex file.
- The foreground color is set for each preview inset.
- The background color is set by \pagecolor in the preamble,
which is understood by pdflatex, but ignored in dvips mode.
Thus dvips is handled with a ps special.
- The tightpage option is necessary to crop the images.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39797 a592a061-630c-0410-9148-cb99ea01b6c8
- Break up steps 1, 2 and 3 from the legacy preview mechanism.
These are really separate steps.
1) Add color info, run latex
2) Run dvips
3) Run ghostscript
- In the case of pdf output, skip step 2 and go directly to step 3.
- Make sure that we fall back to the legacy conversion whenever we can.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39661 a592a061-630c-0410-9148-cb99ea01b6c8
Introduce --debug and --verbose flags to control output. Also, use the
python subprocess module to capture stderr from external commands, thus
bumping the python requirement to version 2.4 or later.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39660 a592a061-630c-0410-9148-cb99ea01b6c8
- Handle the preprocessing in the main lyxpreview script with the
command-line arguments --lilypond and --lilypond-book=exe.
- Remove the obsoleted file lyxpreview-lytex2bitmap.py and the
corresponding lines in configure.py.
Fix for the japanese preview still to come.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39658 a592a061-630c-0410-9148-cb99ea01b6c8
Add command-line arguments in a standard unix fashion, using getopt.
Usage: ./lyxpreview2bitmap.py <options> <input file>
Options:
-h, --help: Show this help screen and exit
--dpi=<res>: Resolution per inch (default: 128)
--png, --ppm: Select the output format (default: png)
--fg=<color>: Foreground color (default: black, ie '000000')
--bg=<color>: Background color (default: white, ie 'ffffff')
--latex=<exe>: Specify the executable for latex (default: latex)
The colors are hexadecimal strings, eg 'faf0e6'.
The changes to PreviewLoader.cpp break the preview of lilypond-book
and japanese files, but they will be handled in the next commits.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39657 a592a061-630c-0410-9148-cb99ea01b6c8
Move some common variables to lyxpreview_tools. Otherwise,
add a few variable names, making it easier to track things.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39656 a592a061-630c-0410-9148-cb99ea01b6c8
Whitespace and line endings only, in preparation for some serious work.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39655 a592a061-630c-0410-9148-cb99ea01b6c8
default option. Also account for the fact that babel may be switched off.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38708 a592a061-630c-0410-9148-cb99ea01b6c8
when latex fails with a preview. Fixes bug #7303 (IP fails with hyperref).
Patch by Ale with suggestions from Enrico
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38243 a592a061-630c-0410-9148-cb99ea01b6c8
- recognize foreground color in pdf route. This is not nice, but there's no better way, AFAICS.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37695 a592a061-630c-0410-9148-cb99ea01b6c8
not correctly handled by dvipng. When a ps special is detected in the dvi
file, the old good legacy method is used. Patch from Ale.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36685 a592a061-630c-0410-9148-cb99ea01b6c8
* src/PreviewLoader.cpp:
- add conditions for preview with pdf output
* lib/scripts/legacy_lyxpreview2ppm.py:
- if no dvi preview file is available, check for a PDF file
and process that, if found
- also produce png output, if requested.
* lib/scripts/lyxpreview2bitmap.py:
- if no dvi preview file is available, check for a PDF file
and process that, if found
* lib/scripts/lyxpreview_tools.py:
- move some common functions here
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25419 a592a061-630c-0410-9148-cb99ea01b6c8