2006-08-08 10:42:59 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2005-10-21 16:11:36 +00:00
|
|
|
|
|
|
|
# file layout2layout.py
|
|
|
|
# This file is part of LyX, the document processor.
|
|
|
|
# Licence details can be found in the file COPYING.
|
|
|
|
|
|
|
|
# author Georg Baum
|
|
|
|
|
|
|
|
# Full author contact details are available in file CREDITS
|
|
|
|
|
2009-02-04 20:06:50 +00:00
|
|
|
# This script will update a .layout file to current format
|
2005-10-21 16:11:36 +00:00
|
|
|
|
2016-07-22 19:52:29 +00:00
|
|
|
# The latest layout format is also defined in src/TextClass.cpp
|
2021-09-19 22:06:20 +00:00
|
|
|
currentFormat = 94
|
2005-10-21 16:11:36 +00:00
|
|
|
|
|
|
|
|
2008-03-24 13:21:26 +00:00
|
|
|
# Incremented to format 4, 6 April 2007, lasgouttes
|
|
|
|
# Introduction of generic "Provides" declaration
|
2005-10-21 16:11:36 +00:00
|
|
|
|
2008-03-24 13:21:26 +00:00
|
|
|
# Incremented to format 5, 22 August 2007 by vermeer
|
|
|
|
# InsetLayout material
|
|
|
|
|
|
|
|
# Incremented to format 6, 7 January 2008 by spitz
|
|
|
|
# Requires tag added to layout files
|
|
|
|
|
|
|
|
# Incremented to format 7, 24 March 2008 by rgh
|
2008-03-24 13:11:16 +00:00
|
|
|
# AddToPreamble tag added to layout files
|
2008-07-25 15:51:27 +00:00
|
|
|
|
|
|
|
# Incremented to format 8, 25 July 2008 by rgh
|
|
|
|
# UseModule tag added to layout files
|
2008-07-28 15:14:37 +00:00
|
|
|
# CopyStyle added to InsetLayout
|
2008-10-05 19:39:09 +00:00
|
|
|
|
|
|
|
# Incremented to format 9, 5 October 2008 by rgh
|
|
|
|
# ForcePlain and CustomPars tags added to InsetLayout
|
|
|
|
|
2008-10-06 14:37:28 +00:00
|
|
|
# Incremented to format 10, 6 October 2008 by rgh
|
|
|
|
# Change format of counters
|
|
|
|
|
2008-10-23 00:27:03 +00:00
|
|
|
# Incremented to format 11, 14 October 2008 by rgh
|
|
|
|
# Add ProvidesModule, ExcludesModule tags
|
|
|
|
|
2009-02-04 20:06:50 +00:00
|
|
|
# Incremented to format 12, 10 January 2009 by gb
|
|
|
|
# Add I18NPreamble tag
|
|
|
|
|
2009-02-06 17:54:33 +00:00
|
|
|
# Incremented to format 13, 5 February 2009 by rgh
|
|
|
|
# Add InToc tag for InsetLayout
|
|
|
|
|
2009-02-17 20:25:56 +00:00
|
|
|
# Incremented to format 14, 14 February 2009 by gb
|
|
|
|
# Rename I18NPreamble to BabelPreamble and add LangPreamble
|
|
|
|
|
2009-05-28 08:59:25 +00:00
|
|
|
# Incremented to format 15, 28 May 2009 by lasgouttes
|
2017-05-13 12:38:01 +00:00
|
|
|
# Add new tag OutputFormat; modules can be conditioned on feature
|
2009-05-28 08:59:25 +00:00
|
|
|
# "from->to".
|
|
|
|
|
2009-06-05 20:07:16 +00:00
|
|
|
# Incremented to format 16, 5 June 2009 by rgh
|
|
|
|
# Add new tags for Text Class:
|
2009-06-19 13:11:06 +00:00
|
|
|
# HTMLPreamble, HTMLAddToPreamble
|
2009-06-05 20:07:16 +00:00
|
|
|
# For Layout:
|
|
|
|
# HTMLTag, HTMLAttr, HTMLLabel, HTMLLabelAttr, HTMLItem, HTMLItemAttr
|
|
|
|
# HTMLStyle, and HTMLPreamble
|
|
|
|
# For InsetLayout:
|
|
|
|
# HTMLTag, HTMLAttr, HTMLStyle, and HTMLPreamble
|
2009-06-19 13:10:36 +00:00
|
|
|
# For Floats:
|
|
|
|
# HTMLType, HTMLClass, HTMLStyle
|
2009-06-05 20:07:16 +00:00
|
|
|
|
2009-10-27 19:03:30 +00:00
|
|
|
# Incremented to format 17, 12 August 2009 by rgh
|
|
|
|
# Add IfStyle and IfCounter tags for layout.
|
|
|
|
|
|
|
|
# Incremented to format 18, 27 October 2009 by rgh
|
2010-01-07 17:32:42 +00:00
|
|
|
# Added some new tags for HTML output.
|
2009-10-27 19:03:30 +00:00
|
|
|
|
2009-12-01 14:34:05 +00:00
|
|
|
# Incremented to format 19, 17 November 2009 by rgh
|
|
|
|
# Added InPreamble tag.
|
|
|
|
|
2009-12-18 00:29:22 +00:00
|
|
|
# Incremented to format 20, 17 December 2009 by rgh
|
|
|
|
# Added ContentAsLabel tag.
|
|
|
|
|
2010-01-12 19:38:31 +00:00
|
|
|
# Incremented to format 21, 12 January 2010 by rgh
|
2010-01-19 19:43:15 +00:00
|
|
|
# Added HTMLTocLayout and HTMLTitle tags.
|
2010-02-13 15:44:17 +00:00
|
|
|
|
2010-01-20 20:33:36 +00:00
|
|
|
# Incremented to format 22, 20 January 2010 by rgh
|
|
|
|
# Added HTMLFormat tag to Counters.
|
2010-01-12 19:38:31 +00:00
|
|
|
|
2010-02-13 15:44:17 +00:00
|
|
|
# Incremented to format 23, 13 February 2010 by spitz
|
|
|
|
# Added Spellcheck tag.
|
|
|
|
|
2010-03-05 17:24:38 +00:00
|
|
|
# Incremented to format 24, 5 March 2010 by rgh
|
2010-03-05 22:58:29 +00:00
|
|
|
# Changed LaTeXBuiltin tag to NeedsFloatPkg and
|
|
|
|
# added new tag ListCommand.
|
2010-03-05 17:24:38 +00:00
|
|
|
|
2010-03-17 12:23:24 +00:00
|
|
|
# Incremented to format 25, 12 March 2010 by rgh
|
|
|
|
# Added RefPrefix tag for layouts and floats.
|
|
|
|
|
2010-03-29 18:37:25 +00:00
|
|
|
# Incremented to format 26, 29 March 2010 by rgh
|
|
|
|
# Added CiteFormat.
|
|
|
|
|
2010-06-04 21:50:08 +00:00
|
|
|
# Incremented to format 27, 4 June 2010 by rgh
|
|
|
|
# Added RequiredArgs tag.
|
|
|
|
|
2010-08-09 21:20:29 +00:00
|
|
|
# Incremented to format 28, 6 August 2010 by lasgouttes
|
|
|
|
# Added ParbreakIsNewline tag for Layout and InsetLayout.
|
|
|
|
|
2010-10-12 14:46:17 +00:00
|
|
|
# Incremented to format 29, 10 August 2010 by rgh
|
|
|
|
# Changed Custom:Style, CharStyle:Style, and Element:Style
|
|
|
|
# uniformly to Flex:Style.
|
|
|
|
|
2010-10-13 15:54:39 +00:00
|
|
|
# Incremented to format 30, 13 August 2010 by rgh
|
|
|
|
# Introduced ResetsFont tag for InsetLayout.
|
|
|
|
|
2011-01-12 22:53:41 +00:00
|
|
|
# Incremented to format 31, 12 January 2011 by rgh
|
|
|
|
# Introducted NoCounter tag.
|
|
|
|
|
2011-01-30 22:22:18 +00:00
|
|
|
# Incremented to format 32, 30 January 2011 by forenr
|
|
|
|
# Added Display tag for InsetLayout
|
|
|
|
|
2011-02-02 22:28:47 +00:00
|
|
|
# Incremented to format 33, 2 February 2011 by rgh
|
|
|
|
# Changed NeedsFloatPkg to UsesFloatPkg
|
|
|
|
|
2011-03-28 15:11:57 +00:00
|
|
|
# Incremented to format 34, 28 March 2011 by rgh
|
|
|
|
# Remove obsolete Fill_(Top|Bottom) tags
|
|
|
|
|
2011-03-28 23:11:54 +00:00
|
|
|
# Incremented to format 35, 28 March 2011 by rgh
|
|
|
|
# Try to add "Flex:" to any flex insets that don't have it.
|
|
|
|
|
2011-12-07 15:05:21 +00:00
|
|
|
# Incremented to format 36, 7 December 2011, by rgh
|
|
|
|
# Added HTMLStyles and AddToHTMLStyles tags.
|
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
# Incremented to format 37, 29 February 2012 by jrioux
|
|
|
|
# Implement the citation engine machinery in layouts.
|
|
|
|
# Change CiteFormat to CiteFormat (default|authoryear|numerical).
|
|
|
|
|
2012-04-10 18:21:01 +00:00
|
|
|
# Incremented to format 38, 08 April 2012 by gb
|
|
|
|
# Introduce LangPreamble and BabelPreamble for InsetLayout.
|
|
|
|
|
2012-04-19 09:56:32 +00:00
|
|
|
# Incremented to format 39, 15 April 2012 by sanda
|
|
|
|
# Introduce styling of branches via "InsetLayout Branch:".
|
|
|
|
|
2012-10-10 17:22:54 +00:00
|
|
|
# Incremented to format 40, 10 October 2012 by rgh
|
|
|
|
# Re-do layout names for layout categories
|
|
|
|
|
2012-11-20 10:49:02 +00:00
|
|
|
# Incremented to format 41, 20 November 2012 by spitz
|
|
|
|
# New Argument syntax
|
|
|
|
|
2012-12-22 10:39:04 +00:00
|
|
|
# Incremented to format 42, 22 December 2012 by spitz
|
|
|
|
# New Style tag "ItemCommand"
|
|
|
|
|
2012-12-30 17:29:02 +00:00
|
|
|
# Incremented to format 43, 30 December 2012 by spitz
|
|
|
|
# Extended InsetCaption format
|
|
|
|
|
2013-02-09 17:28:21 +00:00
|
|
|
# Incremented to format 44, 9 February 2013 by rgh
|
|
|
|
# Remove COUNTER label style; rename as STATIC
|
|
|
|
# Rename TOP_ENVIRONMENT to ABOVE and CENTERED_TOP_ENVIRONMENT to CENTERED
|
|
|
|
|
2013-02-09 19:31:26 +00:00
|
|
|
# Incremented to format 45, 12 February 2013 by rgh
|
|
|
|
# New Tag "NoInsetLayout"
|
|
|
|
|
2013-05-15 05:19:49 +00:00
|
|
|
# Incremented to format 46, 15 May 2013 by gb
|
|
|
|
# New Tag "ForceLocal"
|
|
|
|
|
2013-05-23 13:25:40 +00:00
|
|
|
# Incremented to format 47, 23 May 2013 by rgh
|
|
|
|
# Add PackageOptions tag
|
|
|
|
|
2013-06-01 21:42:08 +00:00
|
|
|
# Incremented to format 48, 31 May 2013 by rgh
|
|
|
|
# Add InitialValue tag for counters
|
|
|
|
|
2014-02-10 21:06:32 +00:00
|
|
|
# Incremented to format 49, 10 Feb 2014 by gb
|
|
|
|
# Change default of "ResetsFont" tag to false
|
|
|
|
|
Fix bugs #8546 and #9055, and introduce new separator inset.
The algorithm used for breaking a paragraph in LaTeX export is changed
for avoiding spurious blank lines causing too much vertical space.
This change is tied to the introduction of a new inset (with two
different specializations) helping in either outputing LaTeX paragraph
breaks or separating environments in LyX. Both of the above goals were
previously achieved by the ---Separator--- layout and can now be
accomplished by the new inset in a more natural way. As an example,
after leaving an environment by hitting the Return key for two times,
a third return automatically inserts a parbreak inset, which is
equivalent to the old separator layout, i.e., it also introduces a
blank line in the output. If this blank line is not wanted, the
parbreak separator can be changed to a plain separator by a right
click of the mouse. Of course, an environment can still be separated
by the following one by using the Alt+P+Return shortcut (or the
corresponding menu key), but now the plain separator inset is used
instead of the old separator layout, such that no blank line occurs in
the LaTeX output.
Old documents are converted such that the LaTeX output remains unchanged.
As a result of this conversion, the old separator layout is replaced by
the new parbreak inset, which may also appear in places where the old
algorithm was introducing blank lines while the new one is not.
Note that not all blank lines were actually affecting the LaTeX output,
because a blank line is simply ignored by the TeX engine when it occurs
in the so called "vertical mode" (e.g., after an alignment environment).
The old ---Separator--- layout is now gone and old layout files using it
are also automatically converted.
Round trip conversions between old and new format should leave a document
unchanged. This means that the new behavior about paragraph breaking is
not "carried back" to the old format. Indeed, this would need introducing
special LaTeX commands in ERT that would accumulate in roundtrip
conversions, horribly cluttering the document. So, when converting a
modified document to old formats, the LaTeX output may slightly differ in
vertical spacing if the document is processed by an old version of LyX.
In other words, forward compatibility is guaranteed, but not backwards.
2014-05-10 21:25:11 +00:00
|
|
|
# Incremented to format 50, 9 May 2014 by forenr
|
|
|
|
# Removal of "Separator" layouts
|
|
|
|
|
2014-05-29 12:10:32 +00:00
|
|
|
# Incremented to format 51, 29 May 2014 by spitz
|
|
|
|
# New Style tag "ToggleIndent"
|
|
|
|
|
2014-12-01 13:56:47 +00:00
|
|
|
# Incremented to format 52, 1 December 2014 by spitz
|
|
|
|
# New InsetLayout tag "ForceOwnlines"
|
|
|
|
|
2014-12-08 08:06:41 +00:00
|
|
|
# Incremented to format 53, 7 December 2014 by spitz
|
|
|
|
# New InsetLayout tag "ObsoletedBy"
|
|
|
|
|
2015-01-11 19:00:45 +00:00
|
|
|
# Incremented to format 54, 11 Jan 2014 by gb
|
|
|
|
# New InsetLayout tag "FixedWidthPreambleEncoding"
|
|
|
|
|
2015-04-20 16:13:49 +00:00
|
|
|
# Incremented to format 55, 20 April 2015 by spitz
|
|
|
|
# New InsetLayout and Layout tags "PassThruChars"
|
|
|
|
|
2015-05-22 08:37:14 +00:00
|
|
|
# Incremented to format 56, 20 May 2015 by spitz
|
2015-05-22 16:59:17 +00:00
|
|
|
# New Float tags "AllowedPlacement", "AllowsWide", "AllowsSideways"
|
2015-05-22 08:37:14 +00:00
|
|
|
|
2015-06-01 14:11:05 +00:00
|
|
|
# Incremented to format 57, 30 May 2015 by spitz
|
|
|
|
# New Layout tag "ParagraphGroup"
|
|
|
|
|
2015-12-04 02:06:28 +00:00
|
|
|
# Incremented to format 58, 5 December 2015, by rgh
|
|
|
|
# New Layout tag "ProvideStyle"
|
|
|
|
# Change "IfStyle" to "ModifyStyle"
|
|
|
|
|
2015-11-03 16:47:25 +00:00
|
|
|
# Incremented to format 59, 22 November 2015 by gm
|
|
|
|
# New Tag "OutlinerName"
|
|
|
|
# New Layout tags "AddToToc", "IsTocCaption"
|
|
|
|
# New Layout argument tag "IsTocCaption"
|
|
|
|
|
2016-03-25 18:22:57 +00:00
|
|
|
# Incremented to format 60, 25 March 2016 by lasgouttes
|
|
|
|
# Rename caption subtype LongTableNoNumber to Unnumbered
|
|
|
|
|
2016-10-14 18:08:12 +00:00
|
|
|
# Incremented to format 61, 14 October 2016 by spitz
|
|
|
|
# New Layout tags "ResumeCounter", "StepMasterCounter"
|
|
|
|
|
2016-10-21 08:39:55 +00:00
|
|
|
# Incremented to format 62, 21 October 2016 by spitz
|
|
|
|
# New Layout argument tag "PassThru"
|
|
|
|
|
2017-01-07 15:44:27 +00:00
|
|
|
# Incremented to format 63, 7 January 2017 by spitz
|
|
|
|
# - New textclass tags CiteFramework, MaxCiteNames (for cite engines)
|
|
|
|
# - Extended InsetCite syntax.
|
|
|
|
|
2017-08-31 10:03:54 +00:00
|
|
|
# Incremented to format 64, 30 August 2017 by rgh
|
|
|
|
# Strip leading and trailing spaces from LabelString,
|
|
|
|
# LabelStringAppendix, and EndLabelString, and LabelCounter,
|
|
|
|
# to conform to what we used to do.
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
# Incremented to format 65, 16 October 2017 by spitz
|
|
|
|
# Color collapsable -> collapsible
|
|
|
|
|
2017-12-28 16:44:54 +00:00
|
|
|
# Incremented to format 66, 28 December 2017 by spitz
|
2017-12-29 09:36:03 +00:00
|
|
|
# New Layout tags "AutoNests ... EndAutoNests" and
|
|
|
|
# "IsAutoNestedBy ... EndIsAutoNestedBy"
|
2017-12-28 16:44:54 +00:00
|
|
|
|
2018-04-14 08:28:22 +00:00
|
|
|
# Incremented to format 67, 14 April 2018 by spitz
|
|
|
|
# New Layout tag "NeedsCProtect"
|
|
|
|
|
2018-05-21 10:46:53 +00:00
|
|
|
# Incremented to format 68, 21 May 2018 by spitz
|
|
|
|
# New Layout tag "AddToCiteEngine"
|
|
|
|
|
2018-08-17 08:22:32 +00:00
|
|
|
# Incremented to format 69, 16 August 2018 by spitz
|
|
|
|
# New argument type "listpreamble"
|
|
|
|
|
2019-03-12 13:08:05 +00:00
|
|
|
# Incremented to format 70, 5 June 2018 by rkh
|
2018-10-04 17:36:01 +00:00
|
|
|
# New InsetLayout tag EditExternal
|
|
|
|
|
2019-03-12 13:08:05 +00:00
|
|
|
# Incremented to format 71, 12 March 2019 by spitz
|
|
|
|
# New [Inset]Layout tag NeedMBoxProtect
|
|
|
|
|
2019-03-26 16:42:56 +00:00
|
|
|
# Incremented to format 72, 26 March 2019 by spitz
|
|
|
|
# New TextClass tag TableStyle
|
|
|
|
|
2019-04-18 08:27:19 +00:00
|
|
|
# Incremented to format 73, 18 April 2019 by spitz
|
|
|
|
# New InsetLayout tag MenuString
|
|
|
|
|
2019-04-18 09:35:03 +00:00
|
|
|
# Incremented to format 74, 18 April 2019 by spitz
|
|
|
|
# New InsetLayout and Argument tag NewlineCmd
|
|
|
|
|
2019-06-02 14:33:06 +00:00
|
|
|
# Incremented to format 75, 2 June 2019 by spitz
|
2019-06-02 16:07:10 +00:00
|
|
|
# New Argument tags FreeSpacing, InsertOnNewline
|
2019-06-02 16:16:30 +00:00
|
|
|
# New InsetLayout tag ParbreakIgnored
|
2019-06-02 14:33:06 +00:00
|
|
|
|
2019-07-08 13:40:17 +00:00
|
|
|
# Incremented to format 76, 8 July 2019 by spitz
|
|
|
|
# New textclass tag BibInToc
|
|
|
|
|
2019-08-06 15:34:16 +00:00
|
|
|
# Incremented to format 77, 6 August 2019 by spitz
|
|
|
|
# New textclass tag PageSize (= default page size)
|
|
|
|
# and textclass option PageSize (= list of available page sizes)
|
|
|
|
|
2019-08-06 17:27:49 +00:00
|
|
|
# Incremented to format 78, 6 August 2019 by spitz
|
|
|
|
# New textclass tag FontsizeFormat
|
|
|
|
|
2019-08-07 14:44:11 +00:00
|
|
|
# Incremented to format 79, 7 August 2019 by spitz
|
|
|
|
# New textclass tag PagesizeFormat
|
|
|
|
|
2019-08-12 10:18:28 +00:00
|
|
|
# Incremented to format 80, 12 August 2019 by spitz
|
|
|
|
# New float option Requires
|
|
|
|
|
2020-07-07 07:49:48 +00:00
|
|
|
# Incremented to format 81, 12 August 2019 by rikiheck
|
2020-05-03 03:14:19 +00:00
|
|
|
# New tag GuiName for counters
|
|
|
|
|
2020-09-11 23:04:43 +00:00
|
|
|
# Incremented to format 82, 4 June 2017 by tcuvelier
|
2020-07-07 07:49:48 +00:00
|
|
|
# - Add new tags for Layout:
|
|
|
|
# DocBookTag, DocBookAttr, DocBookInInfo,
|
|
|
|
# DocBookWrapperTag, DocBookWrapperAttr,
|
|
|
|
# DocBookItemWrapperTag, DocBookItemWrapperAttr,
|
|
|
|
# DocBookItemTag, DocBookItemAttr,
|
|
|
|
# DocBookLabelTag, DocBookLabelAttr
|
|
|
|
# - Removed tag Header from ClassOptionsClassOptions
|
|
|
|
# - Removed tag Element for flex insets
|
|
|
|
|
2020-09-11 23:04:43 +00:00
|
|
|
# Incremented to format 83, 2 August 2020 by tcuvelier
|
2020-08-03 14:04:26 +00:00
|
|
|
# New tags DocBookWrapperMergeWithPrevious and DocBookAbstract
|
2020-08-02 15:07:38 +00:00
|
|
|
|
2020-08-17 21:06:26 +00:00
|
|
|
# Incremented to format 84, 17 August 2020 by tcuvelier
|
|
|
|
# New tags DocBookTagType, DocBookWrapperTagTagType,
|
|
|
|
# DocBookItemWrapperTagTagType, DocBookItemTagTagType,
|
|
|
|
# DocBookLabelTag
|
|
|
|
|
2020-10-07 04:05:22 +00:00
|
|
|
# Incremented to format 85, 7 October 2020 by tcuvelier
|
|
|
|
# New tags DocBookInnerTag, DocBookInnerAttr,
|
|
|
|
# DocBookInnerTagType
|
2020-10-21 12:54:25 +00:00
|
|
|
|
|
|
|
# Incremented to format 86, 20 October 2020 by tcuvelier
|
|
|
|
# New tag DocBookSection.
|
|
|
|
|
2020-11-28 21:43:00 +00:00
|
|
|
# Incremented to format 87, 2 November 2020 by rkh
|
|
|
|
|
|
|
|
# Incremented to format 88, 28 November 2020 by tcuvelier
|
|
|
|
# New tag DocBookNotInPara.
|
2020-11-02 22:36:58 +00:00
|
|
|
|
2020-12-05 21:14:30 +00:00
|
|
|
# Incremented to format 89, 5 December 2020 by rkh
|
|
|
|
# New tag LaTeXName for counters
|
|
|
|
|
2020-12-11 10:44:45 +00:00
|
|
|
# Incremented to format 90, 11 December 2020 by spitz
|
|
|
|
# Use semantic label colors
|
|
|
|
|
2021-01-26 07:42:39 +00:00
|
|
|
# Incremented to format 91, 25 January 2021 by spitz
|
|
|
|
# InputGlobal tag
|
|
|
|
|
2021-01-30 14:56:31 +00:00
|
|
|
# Incremented to format 92, 30 January 2021 by spitz
|
2021-02-13 03:34:03 +00:00
|
|
|
# Add ProvideInsetLayout and ModifyInsetLayout
|
|
|
|
|
|
|
|
# Incremented to format 93, 13 February 2021 by spitz
|
|
|
|
# Add DocBookNoFontInside
|
2021-01-30 14:56:31 +00:00
|
|
|
|
2021-09-19 22:06:20 +00:00
|
|
|
# Incremented to format 94, 19 September 2021 by tcuvelier
|
|
|
|
# Add DocBookFloatType, DocBookCaption
|
|
|
|
|
2009-05-19 23:34:12 +00:00
|
|
|
# Do not forget to document format change in Customization
|
2009-05-28 02:00:04 +00:00
|
|
|
# Manual (section "Declaring a new text class").
|
2009-05-19 23:34:12 +00:00
|
|
|
|
2010-01-14 14:05:50 +00:00
|
|
|
# You might also want to consider running the
|
2014-11-16 11:43:52 +00:00
|
|
|
# development/tools/updatelayouts.py script to update all
|
2010-01-14 14:05:50 +00:00
|
|
|
# layout files to the new format.
|
|
|
|
|
2008-01-10 03:59:39 +00:00
|
|
|
|
2017-04-13 14:20:39 +00:00
|
|
|
import os, re, sys
|
2016-07-22 19:52:29 +00:00
|
|
|
import argparse
|
|
|
|
|
|
|
|
# Provide support for both python 2 and 3
|
|
|
|
# (copied from lyx2lyx)
|
|
|
|
PY2 = sys.version_info[0] == 2
|
|
|
|
if PY2:
|
|
|
|
# argparse returns strings in the commandline encoding, we need to convert.
|
|
|
|
# sys.getdefaultencoding() would not always be correct, see
|
|
|
|
# http://legacy.python.org/dev/peps/pep-0383/
|
|
|
|
def cmd_arg(arg):
|
|
|
|
return arg.decode(sys.getfilesystemencoding())
|
|
|
|
else:
|
|
|
|
cmd_arg = str
|
|
|
|
# End of code to support for both python 2 and 3
|
2005-10-21 16:11:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def error(message):
|
|
|
|
sys.stderr.write(message + '\n')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
2009-06-21 18:23:10 +00:00
|
|
|
def trim_bom(line):
|
|
|
|
" Remove byte order mark."
|
|
|
|
if line[0:3] == "\357\273\277":
|
|
|
|
return line[3:]
|
|
|
|
else:
|
|
|
|
return line
|
|
|
|
|
|
|
|
|
2009-11-13 16:12:04 +00:00
|
|
|
def read(source):
|
2005-10-21 16:11:36 +00:00
|
|
|
" Read input file and strip lineendings."
|
2011-09-12 20:42:22 +00:00
|
|
|
lines = source.read().splitlines() or ['']
|
2009-11-14 19:16:53 +00:00
|
|
|
lines[0] = trim_bom(lines[0])
|
2005-10-21 16:11:36 +00:00
|
|
|
return lines
|
|
|
|
|
|
|
|
|
|
|
|
def write(output, lines):
|
|
|
|
" Write output file with native lineendings."
|
2017-04-13 14:20:39 +00:00
|
|
|
output.write(os.linesep.encode('ascii').join(lines)
|
|
|
|
+ os.linesep.encode('ascii'))
|
2005-10-21 16:11:36 +00:00
|
|
|
|
|
|
|
|
2006-03-29 18:49:27 +00:00
|
|
|
# Concatenates old and new in an intelligent way:
|
|
|
|
# If old is wrapped in ", they are stripped. The result is wrapped in ".
|
|
|
|
def concatenate_label(old, new):
|
|
|
|
# Don't use strip as long as we support python 1.5.2
|
2017-04-13 14:20:39 +00:00
|
|
|
if old[0] == b'"':
|
|
|
|
return old[0:-1] + new + b'"'
|
2006-03-29 18:49:27 +00:00
|
|
|
else:
|
2017-04-13 14:20:39 +00:00
|
|
|
return b'"' + old + new + b'"'
|
2006-03-29 18:49:27 +00:00
|
|
|
|
2020-11-28 21:43:00 +00:00
|
|
|
|
2008-10-07 15:45:08 +00:00
|
|
|
# appends a string to a list unless it's already there
|
|
|
|
def addstring(s, l):
|
|
|
|
if l.count(s) > 0:
|
|
|
|
return
|
|
|
|
l.append(s)
|
|
|
|
|
2006-03-29 18:49:27 +00:00
|
|
|
|
2016-07-22 19:52:29 +00:00
|
|
|
def convert(lines, end_format):
|
2005-10-21 16:11:36 +00:00
|
|
|
" Convert to new format."
|
2017-04-13 14:20:39 +00:00
|
|
|
re_Comment = re.compile(b'^(\\s*)#')
|
|
|
|
re_Counter = re.compile(b'\\s*Counter\\s*', re.IGNORECASE)
|
|
|
|
re_Name = re.compile(b'\\s*Name\\s+(\\S+)\\s*', re.IGNORECASE)
|
|
|
|
re_UseMod = re.compile(b'^\\s*UseModule\\s+(.*)', re.IGNORECASE)
|
|
|
|
re_Empty = re.compile(b'^(\\s*)$')
|
|
|
|
re_Format = re.compile(b'^(\\s*)(Format)(\\s+)(\\S+)', re.IGNORECASE)
|
|
|
|
re_Preamble = re.compile(b'^(\\s*)Preamble', re.IGNORECASE)
|
|
|
|
re_EndPreamble = re.compile(b'^(\\s*)EndPreamble', re.IGNORECASE)
|
|
|
|
re_LangPreamble = re.compile(b'^(\\s*)LangPreamble', re.IGNORECASE)
|
|
|
|
re_EndLangPreamble = re.compile(b'^(\\s*)EndLangPreamble', re.IGNORECASE)
|
|
|
|
re_BabelPreamble = re.compile(b'^(\\s*)BabelPreamble', re.IGNORECASE)
|
|
|
|
re_EndBabelPreamble = re.compile(b'^(\\s*)EndBabelPreamble', re.IGNORECASE)
|
|
|
|
re_MaxCounter = re.compile(b'^(\\s*)(MaxCounter)(\\s+)(\\S+)', re.IGNORECASE)
|
|
|
|
re_LabelType = re.compile(b'^(\\s*)(LabelType)(\\s+)(\\S+)', re.IGNORECASE)
|
|
|
|
re_LabelString = re.compile(b'^(\\s*)(LabelString)(\\s+)(("[^"]+")|(\\S+))', re.IGNORECASE)
|
|
|
|
re_LabelStringAppendix = re.compile(b'^(\\s*)(LabelStringAppendix)(\\s+)(("[^"]+")|(\\S+))', re.IGNORECASE)
|
|
|
|
re_LatexType = re.compile(b'^(\\s*)(LatexType)(\\s+)(\\S+)', re.IGNORECASE)
|
|
|
|
re_Style = re.compile(b'^(\\s*)(Style)(\\s+)(\\S+)', re.IGNORECASE)
|
|
|
|
re_IfStyle = re.compile(b'^(\\s*)IfStyle(\\s+\\S+)', re.IGNORECASE)
|
|
|
|
re_CopyStyle = re.compile(b'^(\\s*)(CopyStyle)(\\s+)(\\S+)', re.IGNORECASE)
|
|
|
|
re_NoStyle = re.compile(b'^(\\s*)(NoStyle)(\\s+)(\\S+)', re.IGNORECASE)
|
|
|
|
re_End = re.compile(b'^(\\s*)(End)(\\s*)$', re.IGNORECASE)
|
|
|
|
re_Provides = re.compile(b'^(\\s*)Provides(\\S+)(\\s+)(\\S+)', re.IGNORECASE)
|
|
|
|
re_CharStyle = re.compile(b'^(\\s*)CharStyle(\\s+)(\\S+)$', re.IGNORECASE)
|
|
|
|
re_CiteFormat = re.compile(b'^(\\s*)(CiteFormat)(?:(\\s*)()|(\\s+)(default|authoryear|numerical))', re.IGNORECASE)
|
|
|
|
re_AMSMaths = re.compile(b'^\\s*Input ams(?:math|def)s.inc\\s*')
|
|
|
|
re_AMSMathsPlain = re.compile(b'^\\s*Input amsmaths-plain.inc\\s*')
|
|
|
|
re_AMSMathsSeq = re.compile(b'^\\s*Input amsmaths-seq.inc\\s*')
|
|
|
|
re_TocLevel = re.compile(b'^(\\s*)(TocLevel)(\\s+)(\\S+)', re.IGNORECASE)
|
|
|
|
re_I18nPreamble = re.compile(b'^(\\s*)I18nPreamble', re.IGNORECASE)
|
|
|
|
re_EndI18nPreamble = re.compile(b'^(\\s*)EndI18nPreamble', re.IGNORECASE)
|
|
|
|
re_Float = re.compile(b'^\\s*Float\\s*$', re.IGNORECASE)
|
|
|
|
re_Type = re.compile(b'\\s*Type\\s+(\\w+)', re.IGNORECASE)
|
|
|
|
re_Builtin = re.compile(b'^(\\s*)LaTeXBuiltin\\s+(\\w*)', re.IGNORECASE)
|
|
|
|
re_True = re.compile(b'^\\s*(?:true|1)\\s*$', re.IGNORECASE)
|
|
|
|
re_InsetLayout = re.compile(b'^\\s*InsetLayout\\s+(?:Custom|CharStyle|Element):(\\S+)\\s*$', re.IGNORECASE)
|
|
|
|
re_ResetsFont = re.compile(b'^(\\s*)ResetsFont(\\s+)(\\S+)$', re.IGNORECASE)
|
2010-10-12 14:46:17 +00:00
|
|
|
# with quotes
|
2017-04-13 14:20:39 +00:00
|
|
|
re_QInsetLayout = re.compile(b'^\\s*InsetLayout\\s+"(?:Custom|CharStyle|Element):([^"]+)"\\s*$', re.IGNORECASE)
|
|
|
|
re_InsetLayout_CopyStyle = re.compile(b'^\\s*CopyStyle\\s+(?:Custom|CharStyle|Element):(\\S+)\\s*$', re.IGNORECASE)
|
|
|
|
re_QInsetLayout_CopyStyle = re.compile(b'^\\s*CopyStyle\\s+"(?:Custom|CharStyle|Element):([^"]+)"\\s*$', re.IGNORECASE)
|
|
|
|
re_NeedsFloatPkg = re.compile(b'^(\\s*)NeedsFloatPkg\\s+(\\w+)\\s*$', re.IGNORECASE)
|
|
|
|
re_Fill = re.compile(b'^\\s*Fill_(?:Top|Bottom).*$', re.IGNORECASE)
|
|
|
|
re_InsetLayout2 = re.compile(b'^\\s*InsetLayout\\s+(\\S+)\\s*$', re.IGNORECASE)
|
2011-03-28 23:11:54 +00:00
|
|
|
# with quotes
|
2017-04-13 14:20:39 +00:00
|
|
|
re_QInsetLayout2 = re.compile(b'^\\s*InsetLayout\\s+"([^"]+)"\\s*$', re.IGNORECASE)
|
|
|
|
re_IsFlex = re.compile(b'\\s*LyXType.*$', re.IGNORECASE)
|
|
|
|
re_CopyStyle2 = re.compile(b'(\\s*CopyStyle\\s+)"?([^"]+)"?\\s*$')
|
|
|
|
re_Separator = re.compile(b'^(?:(-*)|(\\s*))(Separator|EndOfSlide)(?:(-*)|(\\s*))$', re.IGNORECASE)
|
2012-10-10 17:54:26 +00:00
|
|
|
# for categories
|
2017-04-13 14:20:39 +00:00
|
|
|
re_Declaration = re.compile(b'^#\\s*\\Declare\\w+Class.*$')
|
|
|
|
re_ExtractCategory = re.compile(b'^(#\\s*\\Declare\\w+Class(?:\\[[^]]*?\\])?){([^(]+?)\\s+\\(([^)]+?)\\)\\s*}\\s*$')
|
2020-06-21 15:37:23 +00:00
|
|
|
ConvDict = {"article": "Articles", "book" : "Books", "letter" : "Letters", "report": "Reports",
|
2012-10-10 17:54:26 +00:00
|
|
|
"presentation" : "Presentations", "curriculum vitae" : "Curricula Vitae", "handout" : "Handouts"}
|
2012-11-20 10:49:02 +00:00
|
|
|
# Arguments
|
2017-04-13 14:20:39 +00:00
|
|
|
re_OptArgs = re.compile(b'^(\\s*)OptionalArgs(\\s+)(\\d+)\\D*$', re.IGNORECASE)
|
|
|
|
re_ReqArgs = re.compile(b'^(\\s*)RequiredArgs(\\s+)(\\d+)\\D*$', re.IGNORECASE)
|
2017-05-13 12:38:01 +00:00
|
|
|
|
2013-02-09 17:28:21 +00:00
|
|
|
# various changes associated with changing how chapters are handled
|
2017-04-13 14:20:39 +00:00
|
|
|
re_LabelTypeIsCounter = re.compile(b'^(\\s*)LabelType(\\s*)Counter\\s*$', re.IGNORECASE)
|
|
|
|
re_TopEnvironment = re.compile(b'^(\\s*)LabelType(\\s+)Top_Environment\\s*$', re.IGNORECASE)
|
|
|
|
re_CenteredEnvironment = re.compile(b'^(\\s*)LabelType(\\s+)Centered_Top_Environment\\s*$', re.IGNORECASE)
|
|
|
|
re_ChapterStyle = re.compile(b'^\\s*Style\\s+Chapter\\s*$', re.IGNORECASE)
|
|
|
|
re_InsetLayout_CaptionLTNN = re.compile(b'^(\\s*InsetLayout\\s+)(Caption:LongTableNonumber)', re.IGNORECASE)
|
2017-08-31 10:03:54 +00:00
|
|
|
# for format 64
|
|
|
|
re_trimLabelString = re.compile(b'^(\\s*LabelString\s+)"\\s*(.*?)\\s*"\\s*$')
|
|
|
|
re_trimLabelStringAppendix = re.compile(b'^(\\s*LabelStringAppendix\s+)"\\s*(.*?)\\s*"\\s*$')
|
|
|
|
re_trimEndLabelString = re.compile(b'^(\\s*EndLabelString\s+)"\\s*(.*?)\\s*"\\s*$')
|
|
|
|
re_trimLabelCounter = re.compile(b'^(\\s*LabelCounter\s+)"\\s*(.*?)\\s*"\\s*$')
|
2012-10-10 17:54:26 +00:00
|
|
|
|
2005-10-21 16:11:36 +00:00
|
|
|
|
2006-03-29 18:49:27 +00:00
|
|
|
# counters for sectioning styles (hardcoded in 1.3)
|
2017-04-13 14:20:39 +00:00
|
|
|
counters = {b"part" : b"\\Roman{part}",
|
|
|
|
b"chapter" : b"\\arabic{chapter}",
|
|
|
|
b"section" : b"\\arabic{section}",
|
|
|
|
b"subsection" : b"\\arabic{section}.\\arabic{subsection}",
|
|
|
|
b"subsubsection" : b"\\arabic{section}.\\arabic{subsection}.\\arabic{subsubsection}",
|
|
|
|
b"paragraph" : b"\\arabic{section}.\\arabic{subsection}.\\arabic{subsubsection}.\\arabic{paragraph}",
|
|
|
|
b"subparagraph" : b"\\arabic{section}.\\arabic{subsection}.\\arabic{subsubsection}.\\arabic{paragraph}.\\arabic{subparagraph}"}
|
2006-03-29 18:49:27 +00:00
|
|
|
|
|
|
|
# counters for sectioning styles in appendix (hardcoded in 1.3)
|
2017-04-13 14:20:39 +00:00
|
|
|
appendixcounters = {b"chapter" : b"\\Alph{chapter}",
|
|
|
|
b"section" : b"\\Alph{section}",
|
|
|
|
b"subsection" : b"\\arabic{section}.\\arabic{subsection}",
|
|
|
|
b"subsubsection" : b"\\arabic{section}.\\arabic{subsection}.\\arabic{subsubsection}",
|
|
|
|
b"paragraph" : b"\\arabic{section}.\\arabic{subsection}.\\arabic{subsubsection}.\\arabic{paragraph}",
|
|
|
|
b"subparagraph" : b"\\arabic{section}.\\arabic{subsection}.\\arabic{subsubsection}.\\arabic{paragraph}.\\arabic{subparagraph}"}
|
2006-03-29 18:49:27 +00:00
|
|
|
|
|
|
|
# Value of TocLevel for sectioning styles
|
2017-04-13 14:20:39 +00:00
|
|
|
toclevels = {b"part" : -1,
|
|
|
|
b"chapter" : 0,
|
|
|
|
b"section" : 1,
|
|
|
|
b"subsection" : 2,
|
|
|
|
b"subsubsection" : 3,
|
|
|
|
b"paragraph" : 4,
|
|
|
|
b"subparagraph" : 5}
|
2006-03-29 18:49:27 +00:00
|
|
|
|
2005-10-21 16:11:36 +00:00
|
|
|
i = 0
|
|
|
|
only_comment = 1
|
2017-04-13 14:20:39 +00:00
|
|
|
counter = b""
|
|
|
|
toclevel = b""
|
|
|
|
label = b""
|
|
|
|
labelstring = b""
|
|
|
|
labelstringappendix = b""
|
|
|
|
space1 = b""
|
2006-03-29 18:49:27 +00:00
|
|
|
labelstring_line = -1
|
|
|
|
labelstringappendix_line = -1
|
|
|
|
labeltype_line = -1
|
2017-04-13 14:20:39 +00:00
|
|
|
latextype = b""
|
2006-01-19 08:40:10 +00:00
|
|
|
latextype_line = -1
|
2017-04-13 14:20:39 +00:00
|
|
|
style = b""
|
2006-03-29 18:49:27 +00:00
|
|
|
maxcounter = 0
|
2007-01-30 13:23:21 +00:00
|
|
|
format = 1
|
2008-10-07 15:45:08 +00:00
|
|
|
formatline = 0
|
|
|
|
usemodules = []
|
2011-04-15 02:50:45 +00:00
|
|
|
flexstyles = []
|
2012-11-20 10:49:02 +00:00
|
|
|
opts = 0
|
|
|
|
reqs = 0
|
2013-02-09 17:28:21 +00:00
|
|
|
inchapter = False
|
2014-02-10 21:06:32 +00:00
|
|
|
isflexlayout = False # only used for 48 -> 49
|
|
|
|
# Whether a style is inherited (works only for CopyStyle currently,
|
|
|
|
# not for true inherited styles, see bug 8920
|
|
|
|
inherited = False # only used for 48 -> 49
|
|
|
|
resetsfont_found = False # only used for 48 -> 49
|
2008-10-07 15:45:08 +00:00
|
|
|
|
2005-10-21 16:11:36 +00:00
|
|
|
while i < len(lines):
|
2012-10-12 13:49:10 +00:00
|
|
|
# Skip comments and empty lines
|
|
|
|
if (re_Comment.match(lines[i]) or re_Empty.match(lines[i])):
|
|
|
|
# We need to deal with this conversion here, because it happens
|
|
|
|
# inside the initial comment block.
|
|
|
|
if only_comment and format == 39:
|
|
|
|
match = re_ExtractCategory.match(lines[i])
|
|
|
|
if match:
|
|
|
|
lpre = match.group(1)
|
|
|
|
lcat = match.group(2)
|
|
|
|
lnam = match.group(3)
|
|
|
|
if lcat in ConvDict:
|
|
|
|
lcat = ConvDict[lcat]
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = lpre + b"{" + lnam + b"}"
|
|
|
|
lines.insert(i+1, b"# \\DeclareCategory{" + lcat + b"}")
|
2017-05-13 12:38:01 +00:00
|
|
|
i += 1
|
2012-10-12 13:49:10 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
2005-10-21 16:11:36 +00:00
|
|
|
|
2006-01-19 08:40:10 +00:00
|
|
|
# insert file format if not already there
|
2020-06-21 15:37:23 +00:00
|
|
|
if only_comment:
|
2008-10-06 12:16:17 +00:00
|
|
|
match = re_Format.match(lines[i])
|
|
|
|
if match:
|
2008-10-07 15:45:08 +00:00
|
|
|
formatline = i
|
2008-10-06 12:16:17 +00:00
|
|
|
format = int(match.group(4))
|
2020-06-21 15:37:23 +00:00
|
|
|
if 1 < format < end_format:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = b"Format %d" % (format + 1)
|
2008-10-06 12:16:17 +00:00
|
|
|
only_comment = 0
|
2016-07-22 19:52:29 +00:00
|
|
|
elif format == end_format:
|
2008-10-06 12:16:17 +00:00
|
|
|
# nothing to do
|
|
|
|
return format
|
2005-10-21 16:11:36 +00:00
|
|
|
else:
|
2016-07-22 19:52:29 +00:00
|
|
|
error('Cannot convert file format %s to %s' % (format, end_format))
|
2008-10-06 12:16:17 +00:00
|
|
|
else:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines.insert(i, b"Format 2")
|
2008-10-06 12:16:17 +00:00
|
|
|
only_comment = 0
|
|
|
|
continue
|
2005-10-21 16:11:36 +00:00
|
|
|
|
|
|
|
# Don't get confused by LaTeX code
|
|
|
|
if re_Preamble.match(lines[i]):
|
2007-08-22 14:36:07 +00:00
|
|
|
i += 1
|
2005-10-21 16:11:36 +00:00
|
|
|
while i < len(lines) and not re_EndPreamble.match(lines[i]):
|
2007-08-22 14:36:07 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
2009-02-17 20:25:56 +00:00
|
|
|
if re_LangPreamble.match(lines[i]):
|
|
|
|
i += 1
|
|
|
|
while i < len(lines) and not re_EndLangPreamble.match(lines[i]):
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
if re_BabelPreamble.match(lines[i]):
|
|
|
|
i += 1
|
|
|
|
while i < len(lines) and not re_EndBabelPreamble.match(lines[i]):
|
|
|
|
i += 1
|
2012-03-01 00:41:30 +00:00
|
|
|
continue
|
2013-02-21 20:57:59 +00:00
|
|
|
|
2021-09-19 22:06:20 +00:00
|
|
|
if 87 <= format <= 94:
|
2020-11-28 21:43:00 +00:00
|
|
|
# nothing to do.
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2020-11-02 22:36:58 +00:00
|
|
|
if format == 86:
|
|
|
|
if lines[i].lstrip().lower().startswith(b"stepmastercounter"):
|
|
|
|
pattern = re.compile(b"stepmastercounter", re.IGNORECASE)
|
|
|
|
lines[i] = pattern.sub(b"StepParentCounter", lines[i])
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2020-10-07 04:05:22 +00:00
|
|
|
if 82 <= format <= 85:
|
2020-09-28 20:29:28 +00:00
|
|
|
# nothing to do.
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2020-07-07 07:49:48 +00:00
|
|
|
if format == 81:
|
|
|
|
match = re.compile(b'^(\\s*Header\\s+)("?\\w+"?)', re.IGNORECASE).match(lines[i])
|
|
|
|
if match:
|
|
|
|
del lines[i]
|
|
|
|
continue
|
|
|
|
|
|
|
|
match = re.compile(b'(\\s*LyXType\\s+)(\\w+)(\\s*Element\\s+)', re.IGNORECASE).match(lines[i])
|
|
|
|
if match:
|
|
|
|
del lines[i]
|
|
|
|
continue
|
|
|
|
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
|
|
|
if 65 <= format <= 80:
|
2017-12-28 16:44:54 +00:00
|
|
|
# nothing to do.
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
if format == 64:
|
|
|
|
match = re.compile(b'(\\s*Color\\s+)(\\w+)', re.IGNORECASE).match(lines[i])
|
|
|
|
if not match:
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
col = match.group(2)
|
|
|
|
if col == "collapsable":
|
|
|
|
lines[i] = match.group(1) + "collapsible"
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2017-08-31 10:03:54 +00:00
|
|
|
if format == 63:
|
|
|
|
for r in (re_trimLabelString, re_trimLabelStringAppendix,\
|
|
|
|
re_trimEndLabelString, re_trimLabelCounter):
|
|
|
|
m = r.match(lines[i])
|
|
|
|
if m:
|
2017-10-13 08:04:27 +00:00
|
|
|
lines[i] = m.group(1) + b'"' + m.group(2) + b'"'
|
2017-08-31 10:03:54 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2020-06-21 15:37:23 +00:00
|
|
|
if 60 <= format <= 62:
|
2016-10-14 18:08:12 +00:00
|
|
|
# nothing to do.
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2016-03-25 18:22:57 +00:00
|
|
|
if format == 59:
|
|
|
|
match = re_InsetLayout_CaptionLTNN.match(lines[i])
|
|
|
|
if not match:
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
# '^(\s*InsetLayout\s+)(Caption:LongTableNonumber)'
|
|
|
|
lead = match.group(1)
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = lead + b"Caption:Unnumbered"
|
2016-03-25 18:22:57 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2015-11-03 16:47:25 +00:00
|
|
|
if format == 58:
|
|
|
|
# nothing to do.
|
|
|
|
i += 1
|
|
|
|
continue
|
2015-12-04 02:06:28 +00:00
|
|
|
|
|
|
|
if format == 57:
|
|
|
|
match = re_IfStyle.match(lines[i])
|
|
|
|
if not match:
|
|
|
|
i += 1
|
|
|
|
continue
|
2017-04-13 14:20:39 +00:00
|
|
|
# b'^(\\s*)IfStyle(\\s+\\S+)
|
2015-12-04 02:06:28 +00:00
|
|
|
lead = match.group(1)
|
|
|
|
trail = match.group(2)
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = lead + b"ModifyStyle" + trail
|
2015-12-04 02:06:28 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2020-06-21 15:37:23 +00:00
|
|
|
if 50 <= format <= 56:
|
2014-05-29 12:10:32 +00:00
|
|
|
# nothing to do.
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
Fix bugs #8546 and #9055, and introduce new separator inset.
The algorithm used for breaking a paragraph in LaTeX export is changed
for avoiding spurious blank lines causing too much vertical space.
This change is tied to the introduction of a new inset (with two
different specializations) helping in either outputing LaTeX paragraph
breaks or separating environments in LyX. Both of the above goals were
previously achieved by the ---Separator--- layout and can now be
accomplished by the new inset in a more natural way. As an example,
after leaving an environment by hitting the Return key for two times,
a third return automatically inserts a parbreak inset, which is
equivalent to the old separator layout, i.e., it also introduces a
blank line in the output. If this blank line is not wanted, the
parbreak separator can be changed to a plain separator by a right
click of the mouse. Of course, an environment can still be separated
by the following one by using the Alt+P+Return shortcut (or the
corresponding menu key), but now the plain separator inset is used
instead of the old separator layout, such that no blank line occurs in
the LaTeX output.
Old documents are converted such that the LaTeX output remains unchanged.
As a result of this conversion, the old separator layout is replaced by
the new parbreak inset, which may also appear in places where the old
algorithm was introducing blank lines while the new one is not.
Note that not all blank lines were actually affecting the LaTeX output,
because a blank line is simply ignored by the TeX engine when it occurs
in the so called "vertical mode" (e.g., after an alignment environment).
The old ---Separator--- layout is now gone and old layout files using it
are also automatically converted.
Round trip conversions between old and new format should leave a document
unchanged. This means that the new behavior about paragraph breaking is
not "carried back" to the old format. Indeed, this would need introducing
special LaTeX commands in ERT that would accumulate in roundtrip
conversions, horribly cluttering the document. So, when converting a
modified document to old formats, the LaTeX output may slightly differ in
vertical spacing if the document is processed by an old version of LyX.
In other words, forward compatibility is guaranteed, but not backwards.
2014-05-10 21:25:11 +00:00
|
|
|
if format == 49:
|
|
|
|
separator = []
|
|
|
|
|
|
|
|
# delete separator styles
|
|
|
|
match = re_Style.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
style = match.group(4).lower()
|
Fix bugs #8546 and #9055, and introduce new separator inset.
The algorithm used for breaking a paragraph in LaTeX export is changed
for avoiding spurious blank lines causing too much vertical space.
This change is tied to the introduction of a new inset (with two
different specializations) helping in either outputing LaTeX paragraph
breaks or separating environments in LyX. Both of the above goals were
previously achieved by the ---Separator--- layout and can now be
accomplished by the new inset in a more natural way. As an example,
after leaving an environment by hitting the Return key for two times,
a third return automatically inserts a parbreak inset, which is
equivalent to the old separator layout, i.e., it also introduces a
blank line in the output. If this blank line is not wanted, the
parbreak separator can be changed to a plain separator by a right
click of the mouse. Of course, an environment can still be separated
by the following one by using the Alt+P+Return shortcut (or the
corresponding menu key), but now the plain separator inset is used
instead of the old separator layout, such that no blank line occurs in
the LaTeX output.
Old documents are converted such that the LaTeX output remains unchanged.
As a result of this conversion, the old separator layout is replaced by
the new parbreak inset, which may also appear in places where the old
algorithm was introducing blank lines while the new one is not.
Note that not all blank lines were actually affecting the LaTeX output,
because a blank line is simply ignored by the TeX engine when it occurs
in the so called "vertical mode" (e.g., after an alignment environment).
The old ---Separator--- layout is now gone and old layout files using it
are also automatically converted.
Round trip conversions between old and new format should leave a document
unchanged. This means that the new behavior about paragraph breaking is
not "carried back" to the old format. Indeed, this would need introducing
special LaTeX commands in ERT that would accumulate in roundtrip
conversions, horribly cluttering the document. So, when converting a
modified document to old formats, the LaTeX output may slightly differ in
vertical spacing if the document is processed by an old version of LyX.
In other words, forward compatibility is guaranteed, but not backwards.
2014-05-10 21:25:11 +00:00
|
|
|
if re_Separator.match(style):
|
|
|
|
del lines[i]
|
|
|
|
while i < len(lines) and not re_End.match(lines[i]):
|
|
|
|
separator.append(lines[i])
|
|
|
|
del lines[i]
|
|
|
|
if i == len(lines):
|
|
|
|
error('Incomplete separator style.')
|
|
|
|
else:
|
|
|
|
del lines[i]
|
|
|
|
continue
|
|
|
|
|
|
|
|
# delete undefinition of separator styles
|
|
|
|
match = re_NoStyle.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
style = match.group(4).lower()
|
Fix bugs #8546 and #9055, and introduce new separator inset.
The algorithm used for breaking a paragraph in LaTeX export is changed
for avoiding spurious blank lines causing too much vertical space.
This change is tied to the introduction of a new inset (with two
different specializations) helping in either outputing LaTeX paragraph
breaks or separating environments in LyX. Both of the above goals were
previously achieved by the ---Separator--- layout and can now be
accomplished by the new inset in a more natural way. As an example,
after leaving an environment by hitting the Return key for two times,
a third return automatically inserts a parbreak inset, which is
equivalent to the old separator layout, i.e., it also introduces a
blank line in the output. If this blank line is not wanted, the
parbreak separator can be changed to a plain separator by a right
click of the mouse. Of course, an environment can still be separated
by the following one by using the Alt+P+Return shortcut (or the
corresponding menu key), but now the plain separator inset is used
instead of the old separator layout, such that no blank line occurs in
the LaTeX output.
Old documents are converted such that the LaTeX output remains unchanged.
As a result of this conversion, the old separator layout is replaced by
the new parbreak inset, which may also appear in places where the old
algorithm was introducing blank lines while the new one is not.
Note that not all blank lines were actually affecting the LaTeX output,
because a blank line is simply ignored by the TeX engine when it occurs
in the so called "vertical mode" (e.g., after an alignment environment).
The old ---Separator--- layout is now gone and old layout files using it
are also automatically converted.
Round trip conversions between old and new format should leave a document
unchanged. This means that the new behavior about paragraph breaking is
not "carried back" to the old format. Indeed, this would need introducing
special LaTeX commands in ERT that would accumulate in roundtrip
conversions, horribly cluttering the document. So, when converting a
modified document to old formats, the LaTeX output may slightly differ in
vertical spacing if the document is processed by an old version of LyX.
In other words, forward compatibility is guaranteed, but not backwards.
2014-05-10 21:25:11 +00:00
|
|
|
if re_Separator.match(style):
|
|
|
|
del lines[i]
|
|
|
|
continue
|
|
|
|
|
|
|
|
# replace the CopyStyle statement with the definition of the real
|
|
|
|
# style. This may result in duplicate statements, but that is OK
|
|
|
|
# since the second one will overwrite the first one.
|
|
|
|
match = re_CopyStyle.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
style = match.group(4).lower()
|
Fix bugs #8546 and #9055, and introduce new separator inset.
The algorithm used for breaking a paragraph in LaTeX export is changed
for avoiding spurious blank lines causing too much vertical space.
This change is tied to the introduction of a new inset (with two
different specializations) helping in either outputing LaTeX paragraph
breaks or separating environments in LyX. Both of the above goals were
previously achieved by the ---Separator--- layout and can now be
accomplished by the new inset in a more natural way. As an example,
after leaving an environment by hitting the Return key for two times,
a third return automatically inserts a parbreak inset, which is
equivalent to the old separator layout, i.e., it also introduces a
blank line in the output. If this blank line is not wanted, the
parbreak separator can be changed to a plain separator by a right
click of the mouse. Of course, an environment can still be separated
by the following one by using the Alt+P+Return shortcut (or the
corresponding menu key), but now the plain separator inset is used
instead of the old separator layout, such that no blank line occurs in
the LaTeX output.
Old documents are converted such that the LaTeX output remains unchanged.
As a result of this conversion, the old separator layout is replaced by
the new parbreak inset, which may also appear in places where the old
algorithm was introducing blank lines while the new one is not.
Note that not all blank lines were actually affecting the LaTeX output,
because a blank line is simply ignored by the TeX engine when it occurs
in the so called "vertical mode" (e.g., after an alignment environment).
The old ---Separator--- layout is now gone and old layout files using it
are also automatically converted.
Round trip conversions between old and new format should leave a document
unchanged. This means that the new behavior about paragraph breaking is
not "carried back" to the old format. Indeed, this would need introducing
special LaTeX commands in ERT that would accumulate in roundtrip
conversions, horribly cluttering the document. So, when converting a
modified document to old formats, the LaTeX output may slightly differ in
vertical spacing if the document is processed by an old version of LyX.
In other words, forward compatibility is guaranteed, but not backwards.
2014-05-10 21:25:11 +00:00
|
|
|
if re_Separator.match(style):
|
|
|
|
if len(separator) > 0:
|
|
|
|
lines[i:i+1] = separator
|
|
|
|
else:
|
|
|
|
# FIXME: If this style was redefined in an include file,
|
|
|
|
# we should replace the real style and not this default.
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i:i+1] = [b' Category MainText',
|
|
|
|
b' KeepEmpty 1',
|
|
|
|
b' Margin Dynamic',
|
|
|
|
b' LatexType Paragraph',
|
|
|
|
b' LatexName dummy',
|
|
|
|
b' ParIndent MM',
|
|
|
|
b' Align Block',
|
|
|
|
b' LabelType Static',
|
|
|
|
b' LabelString "--- Separate Environment ---"',
|
|
|
|
b' LabelFont',
|
|
|
|
b' Family Roman',
|
|
|
|
b' Series Medium',
|
|
|
|
b' Size Normal',
|
|
|
|
b' Color Blue',
|
|
|
|
b' EndFont',
|
|
|
|
b' HTMLLabel NONE']
|
Fix bugs #8546 and #9055, and introduce new separator inset.
The algorithm used for breaking a paragraph in LaTeX export is changed
for avoiding spurious blank lines causing too much vertical space.
This change is tied to the introduction of a new inset (with two
different specializations) helping in either outputing LaTeX paragraph
breaks or separating environments in LyX. Both of the above goals were
previously achieved by the ---Separator--- layout and can now be
accomplished by the new inset in a more natural way. As an example,
after leaving an environment by hitting the Return key for two times,
a third return automatically inserts a parbreak inset, which is
equivalent to the old separator layout, i.e., it also introduces a
blank line in the output. If this blank line is not wanted, the
parbreak separator can be changed to a plain separator by a right
click of the mouse. Of course, an environment can still be separated
by the following one by using the Alt+P+Return shortcut (or the
corresponding menu key), but now the plain separator inset is used
instead of the old separator layout, such that no blank line occurs in
the LaTeX output.
Old documents are converted such that the LaTeX output remains unchanged.
As a result of this conversion, the old separator layout is replaced by
the new parbreak inset, which may also appear in places where the old
algorithm was introducing blank lines while the new one is not.
Note that not all blank lines were actually affecting the LaTeX output,
because a blank line is simply ignored by the TeX engine when it occurs
in the so called "vertical mode" (e.g., after an alignment environment).
The old ---Separator--- layout is now gone and old layout files using it
are also automatically converted.
Round trip conversions between old and new format should leave a document
unchanged. This means that the new behavior about paragraph breaking is
not "carried back" to the old format. Indeed, this would need introducing
special LaTeX commands in ERT that would accumulate in roundtrip
conversions, horribly cluttering the document. So, when converting a
modified document to old formats, the LaTeX output may slightly differ in
vertical spacing if the document is processed by an old version of LyX.
In other words, forward compatibility is guaranteed, but not backwards.
2014-05-10 21:25:11 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2014-02-10 21:06:32 +00:00
|
|
|
if format == 48:
|
|
|
|
# The default of ResetsFont in LyX changed from true to false,
|
|
|
|
# because it is now used for all InsetLayouts, not only flex ones.
|
|
|
|
# Therefore we need to set it to true for all flex insets which do
|
|
|
|
# do not already have a ResetsFont.
|
|
|
|
match = re_InsetLayout2.match(lines[i])
|
2014-04-25 21:17:10 +00:00
|
|
|
if not match:
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2017-04-13 14:20:39 +00:00
|
|
|
name = match.group(1).lower()
|
|
|
|
if name != b"flex" and name != b"\"flex\"" and name[0:5] != b"flex:" and name [0:6] != b"\"flex:":
|
2014-04-25 21:17:10 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
|
|
|
resetsfont_found = False
|
|
|
|
inherited = False
|
|
|
|
notdone = True
|
|
|
|
while i < len(lines):
|
|
|
|
match = re_ResetsFont.match(lines[i])
|
|
|
|
if match:
|
|
|
|
resetsfont_found = True
|
|
|
|
else:
|
|
|
|
match = re_CopyStyle.match(lines[i])
|
|
|
|
if match:
|
|
|
|
inherited = True
|
2014-02-10 21:06:32 +00:00
|
|
|
else:
|
2014-04-25 21:17:10 +00:00
|
|
|
match = re_End.match(lines[i])
|
|
|
|
if match:
|
|
|
|
break
|
|
|
|
i += 1
|
|
|
|
if not resetsfont_found and not inherited:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines.insert(i, b"\tResetsFont true")
|
2014-04-25 21:17:10 +00:00
|
|
|
|
2014-02-10 21:06:32 +00:00
|
|
|
continue
|
|
|
|
|
2020-06-21 15:37:23 +00:00
|
|
|
if 44 <= format <= 47:
|
2013-02-09 19:31:26 +00:00
|
|
|
# nothing to do.
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2013-02-09 17:28:21 +00:00
|
|
|
if format == 43:
|
|
|
|
match = re_LabelTypeIsCounter.match(lines[i])
|
|
|
|
if match:
|
|
|
|
if inchapter:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = match.group(1) + b"LabelType" + match.group(2) + b"Above"
|
2013-02-09 17:28:21 +00:00
|
|
|
else:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = match.group(1) + b"LabelType" + match.group(2) + b"Static"
|
2013-02-09 17:28:21 +00:00
|
|
|
|
|
|
|
match = re_TopEnvironment.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = match.group(1) + b"LabelType" + match.group(2) + b"Above"
|
2013-02-09 17:28:21 +00:00
|
|
|
|
|
|
|
match = re_CenteredEnvironment.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = match.group(1) + b"LabelType" + match.group(2) + b"Centered"
|
2013-02-09 17:28:21 +00:00
|
|
|
|
|
|
|
if inchapter:
|
|
|
|
match = re_Style.match(lines[i])
|
|
|
|
if match:
|
|
|
|
inchapter = False
|
|
|
|
else:
|
|
|
|
match = re_ChapterStyle.match(lines[i])
|
|
|
|
if match:
|
|
|
|
inchapter = True
|
|
|
|
|
|
|
|
i += 1
|
|
|
|
continue
|
2012-03-01 00:41:30 +00:00
|
|
|
|
2012-12-30 17:29:02 +00:00
|
|
|
if format == 42:
|
2017-04-13 14:20:39 +00:00
|
|
|
if lines[i] == b"InsetLayout Caption":
|
|
|
|
lines[i] = b"InsetLayout Caption:Standard"
|
2012-12-30 17:29:02 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
2017-05-13 12:38:01 +00:00
|
|
|
|
2012-12-22 10:39:04 +00:00
|
|
|
if format == 41:
|
|
|
|
# nothing to do.
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2012-11-20 10:49:02 +00:00
|
|
|
if format == 40:
|
|
|
|
# reset counters on Style beginning
|
|
|
|
match = re_Style.match(lines[i])
|
|
|
|
if match:
|
|
|
|
opts = 0
|
|
|
|
reqs = 0
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
match = re_OptArgs.match(lines[i])
|
|
|
|
if match:
|
|
|
|
# Save number of optional arguments
|
|
|
|
space1 = match.group(1)
|
|
|
|
opts = int(match.group(3))
|
|
|
|
# OptionalArgs 0 > ResetArgs 1
|
|
|
|
if opts == 0:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = space1 + b"ResetArgs\t1"
|
2012-11-20 10:49:02 +00:00
|
|
|
i += 1
|
|
|
|
else:
|
|
|
|
del lines[i]
|
|
|
|
continue
|
|
|
|
match = re_ReqArgs.match(lines[i])
|
|
|
|
if match:
|
|
|
|
# Save number of required arguments
|
|
|
|
space1 = match.group(1)
|
|
|
|
reqs = int(match.group(3))
|
|
|
|
del lines[i]
|
|
|
|
continue
|
|
|
|
# Insert the required number of arguments at the end of the style definition
|
|
|
|
match = re_End.match(lines[i])
|
|
|
|
if match:
|
|
|
|
newarg = ['']
|
|
|
|
# First the optionals (this is the required order pre 2.1)
|
|
|
|
if opts > 0:
|
|
|
|
if opts == 1:
|
2017-04-13 14:20:39 +00:00
|
|
|
newarg = [ b'%sArgument 1' % (space1),
|
|
|
|
b'%s\tLabelString\t\"Optional Layout Argument\"' % (space1),
|
|
|
|
b'%sEndArgument' % (space1)]
|
2012-11-20 10:49:02 +00:00
|
|
|
elif opts > 1:
|
|
|
|
actopt = 1
|
|
|
|
while actopt < (opts + 1):
|
2017-04-13 14:20:39 +00:00
|
|
|
newarg += [ b'%sArgument %d' % (space1, actopt),
|
|
|
|
b'%s\tLabelString\t\"Optional Layout Argument %d\"' % (space1, actopt),
|
|
|
|
b'%sEndArgument' % (space1)]
|
2012-11-20 10:49:02 +00:00
|
|
|
actopt += 1
|
|
|
|
# Now the mandatories
|
|
|
|
if reqs > 0:
|
|
|
|
actopt = opts + 1
|
|
|
|
while actopt < (opts + reqs + 1):
|
2017-04-13 14:20:39 +00:00
|
|
|
newarg += [ b'%sArgument %d' % (space1, actopt),
|
|
|
|
b'%s\tLabelString\t"Required Layout Argument %d"' % (space1, actopt - opts),
|
|
|
|
b'%s\tMandatory\t1' % (space1),
|
|
|
|
b'%sEndArgument' % (space1)]
|
2012-11-20 10:49:02 +00:00
|
|
|
actopt += 1
|
|
|
|
# Since we replace the "End" line, re-add this line
|
|
|
|
if len(newarg) > 1:
|
2017-04-13 14:20:39 +00:00
|
|
|
newarg += [b'End']
|
2012-11-20 10:49:02 +00:00
|
|
|
lines[i:i+1] = newarg
|
|
|
|
i += len(newarg)
|
|
|
|
# Reset the counters
|
|
|
|
opts = 0
|
|
|
|
reqs = 0
|
|
|
|
i += 1
|
|
|
|
continue
|
2017-05-13 12:38:01 +00:00
|
|
|
|
2012-10-10 17:22:54 +00:00
|
|
|
if format == 39:
|
2012-10-12 13:54:49 +00:00
|
|
|
# There is a conversion with format 40, but it is done within the
|
|
|
|
# initial comment block and so is above.
|
2012-10-10 17:54:26 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
2012-04-19 09:56:32 +00:00
|
|
|
|
2012-10-10 17:22:54 +00:00
|
|
|
if format == 37 or format == 38:
|
2012-10-10 17:54:26 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
2012-04-10 18:21:01 +00:00
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
if format == 36:
|
2020-06-21 15:37:23 +00:00
|
|
|
match = re_CiteFormat.match(lines[i])
|
2017-04-13 14:20:39 +00:00
|
|
|
if match and match.group(4) == b"":
|
|
|
|
lines[i] = match.group(0) + b" default"
|
2012-03-01 00:41:30 +00:00
|
|
|
i += 1
|
2009-02-17 20:25:56 +00:00
|
|
|
continue
|
2011-01-30 22:22:18 +00:00
|
|
|
|
2011-12-06 22:38:46 +00:00
|
|
|
if format == 35:
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2011-03-28 23:11:54 +00:00
|
|
|
if format == 34:
|
2012-12-10 16:09:50 +00:00
|
|
|
match = re_QInsetLayout2.match(lines[i])
|
2011-03-28 23:11:54 +00:00
|
|
|
if not match:
|
2012-12-10 16:09:50 +00:00
|
|
|
match = re_InsetLayout2.match(lines[i])
|
2011-03-28 23:11:54 +00:00
|
|
|
if not match:
|
2011-04-15 02:50:45 +00:00
|
|
|
match = re_CopyStyle2.match(lines[i])
|
|
|
|
if not match:
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
style = match.group(2)
|
2017-05-13 12:38:01 +00:00
|
|
|
|
2011-04-15 02:50:45 +00:00
|
|
|
if flexstyles.count(style):
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = match.group(1) + b"\"Flex:" + style + b"\""
|
2011-03-28 23:11:54 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
2011-04-15 02:50:45 +00:00
|
|
|
|
2011-03-28 23:11:54 +00:00
|
|
|
name = match.group(1)
|
2017-04-13 14:20:39 +00:00
|
|
|
names = name.split(b":", 1)
|
|
|
|
if len(names) > 1 and names[0] == b"Flex":
|
2011-03-28 23:11:54 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
|
|
|
isflex = False
|
|
|
|
for j in range(i + 1, len(lines)):
|
|
|
|
if re_IsFlex.match(lines[j]):
|
|
|
|
isflex = True
|
|
|
|
break
|
|
|
|
if re_End.match(lines[j]):
|
|
|
|
break
|
|
|
|
|
|
|
|
if isflex:
|
2011-04-15 02:50:45 +00:00
|
|
|
flexstyles.append(name)
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = b"InsetLayout \"Flex:" + name + b"\""
|
2011-03-28 23:11:54 +00:00
|
|
|
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2011-03-28 15:11:57 +00:00
|
|
|
if format == 33:
|
|
|
|
m = re_Fill.match(lines[i])
|
|
|
|
if m:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = b""
|
2011-03-28 15:11:57 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2011-02-02 22:28:47 +00:00
|
|
|
if format == 32:
|
|
|
|
match = re_NeedsFloatPkg.match(lines[i])
|
|
|
|
if match:
|
|
|
|
space = match.group(1)
|
|
|
|
val = match.group(2)
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = space + b"UsesFloatPkg " + val
|
|
|
|
newval = b'true'
|
|
|
|
if val == b'1' or val.lower() == b'true':
|
|
|
|
newval = b'false'
|
|
|
|
lines.insert(i, space + b"IsPredefined " + newval)
|
2011-02-02 22:28:47 +00:00
|
|
|
i += 1
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2010-10-13 15:54:39 +00:00
|
|
|
# Only new features
|
2020-06-21 15:37:23 +00:00
|
|
|
if 29 <= format <= 31:
|
2010-10-13 15:54:39 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2010-10-12 14:46:17 +00:00
|
|
|
if format == 28:
|
|
|
|
match = re_InsetLayout.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = b"InsetLayout Flex:" + match.group(1)
|
2010-10-12 14:46:17 +00:00
|
|
|
else:
|
|
|
|
match = re_QInsetLayout.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = b"InsetLayout \"Flex:" + match.group(1) + b"\""
|
2011-02-14 01:36:00 +00:00
|
|
|
else:
|
|
|
|
match = re_InsetLayout_CopyStyle.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = b"\tCopyStyle Flex:" + match.group(1)
|
2011-02-14 01:36:00 +00:00
|
|
|
else:
|
|
|
|
match = re_QInsetLayout_CopyStyle.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = b"\tCopyStyle \"Flex:" + match.group(1) + b"\""
|
2010-10-12 14:46:17 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
2017-05-13 12:38:01 +00:00
|
|
|
|
2010-03-17 12:23:24 +00:00
|
|
|
# Only new features
|
2020-06-21 15:37:23 +00:00
|
|
|
if 24 <= format <= 27:
|
2010-10-12 14:46:17 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
2009-02-17 20:25:56 +00:00
|
|
|
|
2010-03-05 17:24:38 +00:00
|
|
|
if format == 23:
|
2010-03-05 22:58:29 +00:00
|
|
|
match = re_Float.match(lines[i])
|
|
|
|
i += 1
|
|
|
|
if not match:
|
|
|
|
continue
|
|
|
|
# we need to do two things:
|
|
|
|
# (i) Convert Builtin to NeedsFloatPkg
|
|
|
|
# (ii) Write ListCommand lines for the builtin floats table and figure
|
|
|
|
builtin = False
|
2017-04-13 14:20:39 +00:00
|
|
|
cmd = b""
|
2010-03-05 22:58:29 +00:00
|
|
|
while True and i < len(lines):
|
|
|
|
m1 = re_End.match(lines[i])
|
|
|
|
if m1:
|
|
|
|
if builtin and cmd:
|
2017-04-13 14:20:39 +00:00
|
|
|
line = b" ListCommand " + cmd
|
2010-03-05 22:58:29 +00:00
|
|
|
lines.insert(i, line)
|
|
|
|
i += 1
|
|
|
|
break
|
|
|
|
m2 = re_Builtin.match(lines[i])
|
|
|
|
if m2:
|
|
|
|
builtin = True
|
|
|
|
ws1 = m2.group(1)
|
|
|
|
arg = m2.group(2)
|
2017-04-13 14:20:39 +00:00
|
|
|
newarg = b""
|
2010-03-05 22:58:29 +00:00
|
|
|
if re_True.match(arg):
|
2017-04-13 14:20:39 +00:00
|
|
|
newarg = b"false"
|
2010-03-05 22:58:29 +00:00
|
|
|
else:
|
2017-04-13 14:20:39 +00:00
|
|
|
newarg = b"true"
|
|
|
|
lines[i] = ws1 + b"NeedsFloatPkg " + newarg
|
2010-03-05 22:58:29 +00:00
|
|
|
m3 = re_Type.match(lines[i])
|
|
|
|
if m3:
|
|
|
|
fltype = m3.group(1)
|
|
|
|
fltype = fltype.lower()
|
2017-04-13 14:20:39 +00:00
|
|
|
if fltype == b"table":
|
|
|
|
cmd = b"listoftables"
|
|
|
|
elif fltype == b"figure":
|
|
|
|
cmd = b"listoffigures"
|
2010-03-05 22:58:29 +00:00
|
|
|
# else unknown, which is why we're doing this
|
|
|
|
i += 1
|
2017-05-13 12:38:01 +00:00
|
|
|
continue
|
|
|
|
|
2009-05-28 08:59:25 +00:00
|
|
|
# This just involved new features, not any changes to old ones
|
2020-06-21 15:37:23 +00:00
|
|
|
if 14 <= format <= 22:
|
2009-05-28 08:59:25 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2009-02-17 20:25:56 +00:00
|
|
|
# Rename I18NPreamble to BabelPreamble
|
|
|
|
if format == 13:
|
|
|
|
match = re_I18nPreamble.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = match.group(1) + b"BabelPreamble"
|
2009-02-17 20:25:56 +00:00
|
|
|
i += 1
|
|
|
|
match = re_EndI18nPreamble.match(lines[i])
|
|
|
|
while i < len(lines) and not match:
|
|
|
|
i += 1
|
|
|
|
match = re_EndI18nPreamble.match(lines[i])
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = match.group(1) + b"EndBabelPreamble"
|
2009-02-17 20:25:56 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
2007-08-22 14:36:07 +00:00
|
|
|
|
2009-02-06 17:54:33 +00:00
|
|
|
# These just involved new features, not any changes to old ones
|
|
|
|
if format == 11 or format == 12:
|
2009-02-04 20:06:50 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2008-10-23 00:27:03 +00:00
|
|
|
if format == 10:
|
|
|
|
match = re_UseMod.match(lines[i])
|
|
|
|
if match:
|
|
|
|
module = match.group(1)
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = b"DefaultModule " + module
|
2008-10-23 00:27:03 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2008-10-06 14:37:28 +00:00
|
|
|
if format == 9:
|
|
|
|
match = re_Counter.match(lines[i])
|
|
|
|
if match:
|
|
|
|
counterline = i
|
|
|
|
i += 1
|
|
|
|
while i < len(lines):
|
|
|
|
namem = re_Name.match(lines[i])
|
|
|
|
if namem:
|
|
|
|
name = namem.group(1)
|
|
|
|
lines.pop(i)
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[counterline] = b"Counter %s" % name
|
2008-10-06 14:37:28 +00:00
|
|
|
# we don't need to increment i
|
|
|
|
continue
|
|
|
|
endem = re_End.match(lines[i])
|
|
|
|
if endem:
|
|
|
|
i += 1
|
|
|
|
break
|
|
|
|
i += 1
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2008-10-07 15:45:08 +00:00
|
|
|
if format == 8:
|
|
|
|
# We want to scan for ams-type includes and, if we find them,
|
|
|
|
# add corresponding UseModule tags to the layout.
|
|
|
|
match = re_AMSMaths.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
addstring(b"theorems-ams", usemodules)
|
|
|
|
addstring(b"theorems-ams-extended", usemodules)
|
|
|
|
addstring(b"theorems-sec", usemodules)
|
2008-10-07 15:45:08 +00:00
|
|
|
lines.pop(i)
|
|
|
|
continue
|
|
|
|
match = re_AMSMathsPlain.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
addstring(b"theorems-starred", usemodules)
|
2008-10-07 15:45:08 +00:00
|
|
|
lines.pop(i)
|
|
|
|
continue
|
|
|
|
match = re_AMSMathsSeq.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
addstring(b"theorems-ams", usemodules)
|
|
|
|
addstring(b"theorems-ams-extended", usemodules)
|
2008-10-07 15:45:08 +00:00
|
|
|
lines.pop(i)
|
|
|
|
continue
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2008-10-05 19:39:09 +00:00
|
|
|
# These just involved new features, not any changes to old ones
|
2020-06-21 15:37:23 +00:00
|
|
|
if 5 <= format <= 7:
|
2008-01-10 03:59:39 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
2007-08-22 14:36:07 +00:00
|
|
|
if format == 4:
|
|
|
|
# Handle conversion to long CharStyle names
|
|
|
|
match = re_CharStyle.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = b"InsetLayout CharStyle:%s" % (match.group(3))
|
2007-08-22 14:36:07 +00:00
|
|
|
i += 1
|
2017-04-13 14:20:39 +00:00
|
|
|
lines.insert(i, b"\tLyXType charstyle")
|
2007-08-22 14:36:07 +00:00
|
|
|
i += 1
|
2017-04-13 14:20:39 +00:00
|
|
|
lines.insert(i, b"")
|
|
|
|
lines[i] = b"\tLabelString %s" % (match.group(3))
|
2007-08-22 14:36:07 +00:00
|
|
|
i += 1
|
2005-10-21 16:11:36 +00:00
|
|
|
continue
|
|
|
|
|
2007-04-06 09:02:23 +00:00
|
|
|
if format == 3:
|
|
|
|
# convert 'providesamsmath x', 'providesmakeidx x', 'providesnatbib x', 'providesurl x' to
|
|
|
|
# 'provides amsmath x', 'provides makeidx x', 'provides natbib x', 'provides url x'
|
|
|
|
# x is either 0 or 1
|
|
|
|
match = re_Provides.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i] = b"%sProvides %s%s%s" % (match.group(1), match.group(2).lower(),
|
2007-04-06 09:02:23 +00:00
|
|
|
match.group(3), match.group(4))
|
2007-08-22 14:36:07 +00:00
|
|
|
i += 1
|
2007-04-06 09:02:23 +00:00
|
|
|
continue
|
|
|
|
|
2007-01-30 13:23:21 +00:00
|
|
|
if format == 2:
|
|
|
|
caption = []
|
|
|
|
|
|
|
|
# delete caption styles
|
|
|
|
match = re_Style.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
style = match.group(4).lower()
|
|
|
|
if style == b"caption":
|
2007-01-30 13:23:21 +00:00
|
|
|
del lines[i]
|
|
|
|
while i < len(lines) and not re_End.match(lines[i]):
|
|
|
|
caption.append(lines[i])
|
|
|
|
del lines[i]
|
|
|
|
if i == len(lines):
|
|
|
|
error('Incomplete caption style.')
|
|
|
|
else:
|
|
|
|
del lines[i]
|
|
|
|
continue
|
|
|
|
|
|
|
|
# delete undefinition of caption styles
|
|
|
|
match = re_NoStyle.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
style = match.group(4).lower()
|
|
|
|
if style == b"caption":
|
2007-01-30 13:23:21 +00:00
|
|
|
del lines[i]
|
|
|
|
continue
|
|
|
|
|
|
|
|
# replace the CopyStyle statement with the definition of the real
|
|
|
|
# style. This may result in duplicate statements, but that is OK
|
|
|
|
# since the second one will overwrite the first one.
|
|
|
|
match = re_CopyStyle.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
style = match.group(4).lower()
|
|
|
|
if style == b"caption":
|
2007-01-30 13:23:21 +00:00
|
|
|
if len(caption) > 0:
|
|
|
|
lines[i:i+1] = caption
|
|
|
|
else:
|
|
|
|
# FIXME: This style comes from an include file, we
|
|
|
|
# should replace the real style and not this default.
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[i:i+1] = [b' Margin First_Dynamic',
|
|
|
|
b' LatexType Command',
|
|
|
|
b' LatexName caption',
|
|
|
|
b' NeedProtect 1',
|
|
|
|
b' LabelSep xx',
|
|
|
|
b' ParSkip 0.4',
|
|
|
|
b' TopSep 0.5',
|
|
|
|
b' Align Center',
|
|
|
|
b' AlignPossible Center',
|
|
|
|
b' LabelType Sensitive',
|
|
|
|
b' LabelString "Senseless!"',
|
|
|
|
b' OptionalArgs 1',
|
|
|
|
b' LabelFont',
|
|
|
|
b' Series Bold',
|
|
|
|
b' EndFont']
|
2007-01-30 13:23:21 +00:00
|
|
|
|
2007-08-22 14:36:07 +00:00
|
|
|
i += 1
|
2007-01-30 13:23:21 +00:00
|
|
|
continue
|
|
|
|
|
2006-03-29 18:49:27 +00:00
|
|
|
# Delete MaxCounter and remember the value of it
|
|
|
|
match = re_MaxCounter.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
level = match.group(4).lower()
|
|
|
|
if level == b"counter_chapter":
|
2006-03-29 18:49:27 +00:00
|
|
|
maxcounter = 0
|
2017-04-13 14:20:39 +00:00
|
|
|
elif level == b"counter_section":
|
2006-03-29 18:49:27 +00:00
|
|
|
maxcounter = 1
|
2017-04-13 14:20:39 +00:00
|
|
|
elif level == b"counter_subsection":
|
2006-03-29 18:49:27 +00:00
|
|
|
maxcounter = 2
|
2017-04-13 14:20:39 +00:00
|
|
|
elif level == b"counter_subsubsection":
|
2006-03-29 18:49:27 +00:00
|
|
|
maxcounter = 3
|
2017-04-13 14:20:39 +00:00
|
|
|
elif level == b"counter_paragraph":
|
2006-03-29 18:49:27 +00:00
|
|
|
maxcounter = 4
|
2017-04-13 14:20:39 +00:00
|
|
|
elif level == b"counter_subparagraph":
|
2006-03-29 18:49:27 +00:00
|
|
|
maxcounter = 5
|
2017-04-13 14:20:39 +00:00
|
|
|
elif level == b"counter_enumi":
|
2006-03-29 18:49:27 +00:00
|
|
|
maxcounter = 6
|
2017-04-13 14:20:39 +00:00
|
|
|
elif level == b"counter_enumii":
|
2006-03-29 18:49:27 +00:00
|
|
|
maxcounter = 7
|
2017-04-13 14:20:39 +00:00
|
|
|
elif level == b"counter_enumiii":
|
2006-03-29 18:49:27 +00:00
|
|
|
maxcounter = 8
|
2005-10-21 16:11:36 +00:00
|
|
|
del lines[i]
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Replace line
|
|
|
|
#
|
|
|
|
# LabelType Counter_EnumI
|
|
|
|
#
|
|
|
|
# with two lines
|
|
|
|
#
|
|
|
|
# LabelType Counter
|
|
|
|
# LabelCounter EnumI
|
|
|
|
#
|
|
|
|
match = re_LabelType.match(lines[i])
|
|
|
|
if match:
|
|
|
|
label = match.group(4)
|
2006-03-29 18:49:27 +00:00
|
|
|
# Remember indenting space for later reuse in added lines
|
2006-01-08 15:35:38 +00:00
|
|
|
space1 = match.group(1)
|
2006-03-29 18:49:27 +00:00
|
|
|
# Remember the line for adding the LabelCounter later.
|
|
|
|
# We can't do it here because it could shift latextype_line etc.
|
|
|
|
labeltype_line = i
|
2017-04-13 14:20:39 +00:00
|
|
|
if label[:8].lower() == b"counter_":
|
|
|
|
counter = label[8:].lower()
|
|
|
|
lines[i] = re_LabelType.sub(b'\\1\\2\\3Counter', lines[i])
|
2005-10-21 16:11:36 +00:00
|
|
|
|
2006-03-29 18:49:27 +00:00
|
|
|
# Remember the LabelString line
|
|
|
|
match = re_LabelString.match(lines[i])
|
|
|
|
if match:
|
|
|
|
labelstring = match.group(4)
|
|
|
|
labelstring_line = i
|
|
|
|
|
|
|
|
# Remember the LabelStringAppendix line
|
|
|
|
match = re_LabelStringAppendix.match(lines[i])
|
|
|
|
if match:
|
|
|
|
labelstringappendix = match.group(4)
|
|
|
|
labelstringappendix_line = i
|
|
|
|
|
|
|
|
# Remember the LatexType line
|
2006-01-08 15:35:38 +00:00
|
|
|
match = re_LatexType.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
latextype = match.group(4).lower()
|
2006-01-19 08:40:10 +00:00
|
|
|
latextype_line = i
|
2006-03-29 18:49:27 +00:00
|
|
|
|
2009-02-04 20:06:50 +00:00
|
|
|
# Remember the TocLevel line
|
|
|
|
match = re_TocLevel.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
toclevel = match.group(4).lower()
|
2009-02-04 20:06:50 +00:00
|
|
|
|
2006-03-29 18:49:27 +00:00
|
|
|
# Reset variables at the beginning of a style definition
|
2006-01-08 15:35:38 +00:00
|
|
|
match = re_Style.match(lines[i])
|
|
|
|
if match:
|
2017-04-13 14:20:39 +00:00
|
|
|
style = match.group(4).lower()
|
|
|
|
counter = b""
|
|
|
|
toclevel = b""
|
|
|
|
label = b""
|
|
|
|
space1 = b""
|
|
|
|
labelstring = b""
|
|
|
|
labelstringappendix = b""
|
2006-03-29 18:49:27 +00:00
|
|
|
labelstring_line = -1
|
|
|
|
labelstringappendix_line = -1
|
|
|
|
labeltype_line = -1
|
2017-04-13 14:20:39 +00:00
|
|
|
latextype = b""
|
2006-01-19 08:40:10 +00:00
|
|
|
latextype_line = -1
|
2006-03-29 18:49:27 +00:00
|
|
|
|
|
|
|
if re_End.match(lines[i]):
|
|
|
|
|
|
|
|
# Add a line "LatexType Bib_Environment" if LabelType is Bibliography
|
|
|
|
# (or change the existing LatexType)
|
2017-04-13 14:20:39 +00:00
|
|
|
if label.lower() == b"bibliography":
|
2006-03-29 18:49:27 +00:00
|
|
|
if (latextype_line < 0):
|
2017-04-13 14:20:39 +00:00
|
|
|
lines.insert(i, b"%sLatexType Bib_Environment" % space1)
|
2007-08-22 14:36:07 +00:00
|
|
|
i += 1
|
2006-03-29 18:49:27 +00:00
|
|
|
else:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines[latextype_line] = re_LatexType.sub(b'\\1\\2\\3Bib_Environment', lines[latextype_line])
|
2006-03-29 18:49:27 +00:00
|
|
|
|
2006-04-13 08:54:50 +00:00
|
|
|
# Change "LabelType Static" to "LabelType Itemize" for itemize environments
|
2017-04-13 14:20:39 +00:00
|
|
|
if latextype == b"item_environment" and label.lower() == b"static":
|
|
|
|
lines[labeltype_line] = re_LabelType.sub(b'\\1\\2\\3Itemize', lines[labeltype_line])
|
2006-04-13 08:54:50 +00:00
|
|
|
|
|
|
|
# Change "LabelType Counter_EnumI" to "LabelType Enumerate" for enumerate environments
|
2017-04-13 14:20:39 +00:00
|
|
|
if latextype == b"item_environment" and label.lower() == b"counter_enumi":
|
|
|
|
lines[labeltype_line] = re_LabelType.sub(b'\\1\\2\\3Enumerate', lines[labeltype_line])
|
2006-04-13 08:54:50 +00:00
|
|
|
# Don't add the LabelCounter line later
|
|
|
|
counter = ""
|
|
|
|
|
2006-03-29 18:49:27 +00:00
|
|
|
# Replace
|
|
|
|
#
|
|
|
|
# LabelString "Chapter"
|
|
|
|
#
|
|
|
|
# with
|
|
|
|
#
|
|
|
|
# LabelString "Chapter \arabic{chapter}"
|
|
|
|
#
|
|
|
|
# if this style has a counter. Ditto for LabelStringAppendix.
|
|
|
|
# This emulates the hardcoded article style numbering of 1.3
|
|
|
|
#
|
2017-04-13 14:20:39 +00:00
|
|
|
if counter != b"":
|
2011-02-14 02:28:13 +00:00
|
|
|
if style in counters:
|
2006-03-29 18:49:27 +00:00
|
|
|
if labelstring_line < 0:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines.insert(i, b'%sLabelString "%s"' % (space1, counters[style]))
|
2007-08-22 14:36:07 +00:00
|
|
|
i += 1
|
2006-03-29 18:49:27 +00:00
|
|
|
else:
|
|
|
|
new_labelstring = concatenate_label(labelstring, counters[style])
|
|
|
|
lines[labelstring_line] = re_LabelString.sub(
|
2017-04-13 14:20:39 +00:00
|
|
|
b'\\1\\2\\3%s' % new_labelstring.replace(b"\\", b"\\\\"),
|
2006-03-29 18:49:27 +00:00
|
|
|
lines[labelstring_line])
|
2011-02-14 02:28:13 +00:00
|
|
|
if style in appendixcounters:
|
2006-03-29 18:49:27 +00:00
|
|
|
if labelstringappendix_line < 0:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines.insert(i, b'%sLabelStringAppendix "%s"' % (space1, appendixcounters[style]))
|
2007-08-22 14:36:07 +00:00
|
|
|
i += 1
|
2006-03-29 18:49:27 +00:00
|
|
|
else:
|
|
|
|
new_labelstring = concatenate_label(labelstring, appendixcounters[style])
|
|
|
|
lines[labelstringappendix_line] = re_LabelStringAppendix.sub(
|
2017-04-13 14:20:39 +00:00
|
|
|
b'\\1\\2\\3%s' % new_labelstring.replace(b"\\", b"\\\\"),
|
2006-03-29 18:49:27 +00:00
|
|
|
lines[labelstringappendix_line])
|
|
|
|
|
|
|
|
# Now we can safely add the LabelCounter line
|
2017-04-13 14:20:39 +00:00
|
|
|
lines.insert(labeltype_line + 1, b"%sLabelCounter %s" % (space1, counter))
|
2007-08-22 14:36:07 +00:00
|
|
|
i += 1
|
2006-03-29 18:49:27 +00:00
|
|
|
|
|
|
|
# Add the TocLevel setting for sectioning styles
|
2017-04-13 14:20:39 +00:00
|
|
|
if toclevel == b"" and style in toclevels and maxcounter <= toclevels[style]:
|
|
|
|
lines.insert(i, b'%s\tTocLevel %d' % (space1, toclevels[style]))
|
2007-08-22 14:36:07 +00:00
|
|
|
i += 1
|
2006-01-08 15:35:38 +00:00
|
|
|
|
2007-08-22 14:36:07 +00:00
|
|
|
i += 1
|
2005-10-21 16:11:36 +00:00
|
|
|
|
2011-09-12 20:42:22 +00:00
|
|
|
if only_comment:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines.insert(i, b"Format 2")
|
2008-10-07 15:45:08 +00:00
|
|
|
if usemodules:
|
|
|
|
i = formatline + 1
|
|
|
|
for mod in usemodules:
|
2017-04-13 14:20:39 +00:00
|
|
|
lines.insert(i, b"UseModule " + mod)
|
2008-10-07 15:45:08 +00:00
|
|
|
i += 1
|
|
|
|
|
2007-03-24 12:39:45 +00:00
|
|
|
return format + 1
|
|
|
|
|
2005-10-21 16:11:36 +00:00
|
|
|
|
|
|
|
def main(argv):
|
2016-07-22 19:52:29 +00:00
|
|
|
args = {}
|
|
|
|
args["description"] = "Convert layout file <inputfile> to a newer format."
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(**args)
|
|
|
|
|
2017-05-13 14:25:44 +00:00
|
|
|
parser.add_argument("-t", "--to", type=int, dest="format", default= currentFormat,
|
2016-07-22 19:52:29 +00:00
|
|
|
help=("destination layout format, default %i (latest)") % currentFormat)
|
|
|
|
parser.add_argument("input_file", nargs='?', type=cmd_arg, default=None,
|
|
|
|
help="input file (default stdin)")
|
|
|
|
parser.add_argument("output_file", nargs='?', type=cmd_arg, default=None,
|
|
|
|
help="output file (default stdout)")
|
|
|
|
|
2017-05-13 14:25:44 +00:00
|
|
|
options = parser.parse_args(argv[1:])
|
2005-10-21 16:11:36 +00:00
|
|
|
|
|
|
|
# Open files
|
2016-07-22 19:52:29 +00:00
|
|
|
if options.input_file:
|
|
|
|
source = open(options.input_file, 'rb')
|
2019-07-07 18:37:12 +00:00
|
|
|
elif PY2:
|
2009-11-13 16:12:04 +00:00
|
|
|
source = sys.stdin
|
2019-07-07 18:37:12 +00:00
|
|
|
else:
|
|
|
|
source = sys.stdin.buffer
|
2016-07-22 19:52:29 +00:00
|
|
|
|
|
|
|
if options.output_file:
|
|
|
|
output = open(options.output_file, 'wb')
|
2019-07-07 18:37:12 +00:00
|
|
|
elif PY2:
|
2005-10-21 16:11:36 +00:00
|
|
|
output = sys.stdout
|
2019-07-07 18:37:12 +00:00
|
|
|
else:
|
|
|
|
output = sys.stdout.buffer
|
2016-07-22 19:52:29 +00:00
|
|
|
|
2017-05-13 14:25:44 +00:00
|
|
|
if options.format > currentFormat:
|
|
|
|
error("Format %i does not exist" % options.format);
|
2005-10-21 16:11:36 +00:00
|
|
|
|
|
|
|
# Do the real work
|
2009-11-13 16:12:04 +00:00
|
|
|
lines = read(source)
|
2007-03-24 12:39:45 +00:00
|
|
|
format = 1
|
2017-05-13 14:25:44 +00:00
|
|
|
while (format < options.format):
|
|
|
|
format = convert(lines, options.format)
|
2005-10-21 16:11:36 +00:00
|
|
|
write(output, lines)
|
|
|
|
|
|
|
|
# Close files
|
2016-07-22 19:52:29 +00:00
|
|
|
if options.input_file:
|
2009-11-13 16:12:04 +00:00
|
|
|
source.close()
|
2016-07-22 19:52:29 +00:00
|
|
|
if options.output_file:
|
2005-10-21 16:11:36 +00:00
|
|
|
output.close()
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main(sys.argv)
|