Search:   Help

Developers' side bar

Selected categories

Edit

Shared groups

Links

XML

Categories: Development, LyX_2_1
<< | Page list | >>

Almost from the very beginning, there have been recurrent proposals to switch to an XML based format for LyX files. So far, no steps towards it have been made.

Table of contents (hide)

  1.   1.  Advantages and drawbacks
  2.   2.  Real world example
  3.   3.  Active questions
  4.   4.  Road to an XML format
  5.   5.  Testing tips
    1.   5.1  Command sequences
  6.   6.  Categories

1.  Advantages and drawbacks

Here are some key advantages of switching to an XML based format:

  • XML is an industry standard, while LyX's own format is not used outside the program.
  • There are many well tested tools to validate and manipulate XML
  • XML tags are more easily converted by something like Pandoc. At the time of writing, there doesn't seem to be a LyX parser for Pandoc, and this transition could help.
  • LyX's current format doesn't represent "encapsulation": we only know that an element is inside a section because the section title precedes it, and not because it's actually inside.

Here are some drawbacks:

  • Migration will take considerable effort and introduce many bugs. We would be back at square one(.5 maybe).
  • Theoretically doesn't break user space, because users need not even notice. But eventually something will break.

2.  Real world example

Here is a sample LyX document in the normal format

\lyxformat 620
\begin_document
\begin_header
\inputencoding utf8
\fontencoding auto
\spacing single
\use_hyperref false
\end_header
\begin_body
\begin_layout Title
Example document
\end_layout
\begin_layout Standard
Here are some formulas
\end_layout
\begin_layout Section
Some formulas
\end_layout
\begin_layout Standard
\begin_inset Formula
Hello i'm a formula.
\end_inset
\end_layout
\end_body
\end_document

Here is a way it could look with XML:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE document PUBLIC "-//LyX//DTD lyx//EN" "http://www.lyx.org/lyxformat-620.dtd">
<document>
<head>
<param name="inputencoding">utf8</param>
<param name="fontencoding">auto</param>
<param name="spacing">single</param>
<param name="use_hyperref">false</param>
</head>
<body>
<layout type="Title">Example document</layout>
<layout type="Standard">Here are some formulas</layout>
<section>
<layout type="Section">Some formulas</layout>
<layout type="Standard"><inset type="Formula">Hello i'm a formula.</inset></layout>
</section>
</body>
</document>

3.  Active questions

Here are some questions we need to answer before:

  • <layout type="Standard">Hello</layout>
    <inset type="Formula">Hi</inset>
    or
    <p>Hello</p>
    <formula>Hi</formula>
    ?
  • XML formats for documents already exist! Take a look here: Document file format. Out of them, the one that LyX can realistically use is DocBook. We can write a layer on top of the existing schema: Click me!(approve sites).
  • Why? What does this solve? [Author's own opinion here] In short, nothing. In the long run, however, it could help a lot. I have tried many (MANY!) document editors, and none come close to LyX in practicity, easiness to use, etc. It really is a marvel of an editor. However, LyX is tied to LaTeX. But times are a-changing, TeX is showing it's age (see typst), and more output formats are required. LyX can output to HTML and Docbook magnificently, but it's interface is very much tied to LaTeX. My question is: what if LyX was a general editor which outputted in a general format that a universal markup converter could translate to other formats? LyX could just output to that and have external converter do the conversion work. We would lose a lot of control, and probably it won't appeal anymore to a lot of the user base. Still, a question worth pondering... Is there a way to save the goat AND the cabbage?

4.  Road to an XML format

The first step should be to change the current format meta-characters \ to an intermediate format where the meta-characters are those of XML <&>

Some examples:

  • \lyxformat<lyxformat>
  • \backslask\
  • <, >, &&lt;, &gt;, &amp;

5.  Testing tips

5.1  Command sequences

  • Command that instructs LyX to open a file and save it under a different name. The file is deleted first to avoid a question about overwriting the output file.
    fin=in.lyx
    fout=/tmp/out.lyx
    rm -f $fout
    lyx -x "command-sequence file-open $fin; buffer-write-as $fout; lyx-quit;"
    
    Note: An extra argument -lyxdir <path-to-lyxdir/lib> may be needed.

6.  Categories

Category: Development, LyX_2_1

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2024-03-29 16:57 UTC