Go to page:

Search:   Help



LyX documentation


Shared groups



Categories: scripts, pLyX system
<< | Page list | >>

The pLyX system launches python scripts from the main document window of LyX to manipulate the current document.

The pLyX system v.2

The pLyX system is a scripting system of sorts for LyX. It is built from tools that LyX provides modules, custom insets, file formats, the converter mechanism. Once set up it allows python scripts launched from the main document window to manipulate a copy of the current document, and so to do things with LyX documents that are not (as yet) natively supported.

Using LyX's converter mechanism it is possible to export a LyX file to a LyX file of the same name. The trick is to use a pseudonym for the exported file format -- it's really LyX format, but call it pLyX (pseudonymous LyX). That is enough to fool LyX into exporting from myfile.lyx to myfile.lyx. (That LyX exports to a temporary directory is what makes this possible.) The converted file is a LyX file and can be read in LyX, either in a second instance of the program or in a new tab in the current instance. The speed of modern computers means the main delay in the process is the final step, the launch of the second instance of LyX or the opening of the new tab.

There are many possible manipulations of a file during export and hence, potentially, many possible python scripts. To avoid clogging the file format and converter lists, the pLyX system uses a master script (pLyX.py) to call the different sub-scripts. In version 2 of the system, the call is made in a custom inset inserted near the start of a document and treated like a command line. The name of the sub-script is entered, along with any options. A click of a button on the View/Update toolbar sets everything in motion (click the View other formats button and select View pLyX).


The system consists of the "master" python script, pLyX.py, two associated scripts, and various sub-scripts and their help files. There is also a LyX module pLyX.module containing definitions of two custom insets, one to act like a command line, the other a general purpose container. These files and an explanatory document can be found in a zipped archive at "The pLyX system". Setting up the system involves unzipping the archive to a directory of convenience, then copying the contents of the archive folders to the corresponding folders of your personal LyX2.2 directory. There is also a new file format to be created (pLyX) and its associated converter to be added, plus a final reconfigure. The details are in the document pLyX2.lyx in the doc folder of the archive, readable in LyX 2.2.0 or later.


The zipped archive "The pLyX system" currently contains the following sub-scripts.

align.py Align figures and tables throughout a document, in particular centre/center them. anon.py Anonymize a document by shuffling its alphanumeric characters using a "running anagram" to render the text unreadable while preserving document structure and retaining paragraph length as closely as possible. anonmath.py Anonymize mathematics by changing all single-character variables and functions to a given character, optionally maintaining case, all digits to a given digit, all trig. etc. functions to a given function. The idea is to maintain formula structure but make it unintelligible. autoindx.py Index semi-automatically by inserting index insets adjacent to every occurrence of terms from a specified list of terms. calcul8.py Calculate formulas; a toy, but useful for gaining familiarity with the pLyX process. It can handle scientific-calculator functions and complex numbers. freqchar.py Count the frequency of occurrence of the different characters occurring in a document and present the result in a variety of different forms at the end of the document. freqword.py Count the frequency of occurrence of the different words occurring in a document and present the result in a list at the end of the document. logos.py Change the typed forms of the names LyX, TeX, LaTeX and LaTeX2e into the logofied forms, and vice versa. This is especially relevant in LyX 2.2 where the handling of these logos has changed. replmath.py (Find and) replace elements of maths insets, e.g. change the symbol used for a variable throughout a document, change eqnarrays into AMS align environments, romanise differential coefficients, etc. shuffle.py Shuffle (i.e., randomize) lists, as might be used for voting papers or multi-choice questionaires. The shuffling can be restricted to sub-levels if desired. sortlist.py Sort lists, alphabetically or numerically, ascending or descending, case sensitively or not. Sorts to all six levels of depth if wanted. sorttab.py Sort tables according to the values in specified columns. Allows primary, secondary, tertiary, etc. sorts, alphabetically or numerically, ascending or descending, case sensitively or not.


Category: scripts pLyX system

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2016-06-05 06:58 CEST