Introduce basic support for microtype.sty.

https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg192743.html
This commit is contained in:
Pavel Sanda 2016-06-02 22:40:21 -07:00
parent 6a2219bc6f
commit ba2b86fa5d
12 changed files with 178 additions and 56 deletions

View File

@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
-----------------------
2016-06-16 Pavel Sanda <sanda@lyx.org>
* Format incremented to 509.
New parameter "\use_microtype bool" for including microtype LaTeX
package into preamble.
2016-04-05 Enrico Forestieri <forenr@lyx.org>
* Format incremented to 508
New kind of Separator inset (latexpar). The old parbreak separator

View File

@ -33,7 +33,7 @@ try:
import lyx2lyx_version
version__ = lyx2lyx_version.version
except: # we are running from build directory so assume the last version
version__ = '2.2'
version__ = '2.3'
default_debug__ = 2
@ -86,7 +86,8 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)),
("1_6", list(range(277,346)), minor_versions("1.6" , 10)),
("2_0", list(range(346,414)), minor_versions("2.0" , 8)),
("2_1", list(range(414,475)), minor_versions("2.1" , 5)),
("2_2", list(range(475,509)), minor_versions("2.2" , 0))
("2_2", list(range(475,509)), minor_versions("2.2" , 0)),
("2_3", list(range(509,510)), minor_versions("2.3" , 0))
]
####################################################################

View File

@ -33,6 +33,7 @@ dist_lyx2lyx_PYTHON = \
lyx_2_0.py \
lyx_2_1.py \
lyx_2_2.py \
lyx_2_3.py \
profiling.py \
test_parser_tools.py

75
lib/lyx2lyx/lyx_2_3.py Normal file
View File

@ -0,0 +1,75 @@
# -*- coding: utf-8 -*-
# This file is part of lyx2lyx
# -*- coding: utf-8 -*-
# Copyright (C) 2016 The LyX team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" Convert files to the file format generated by lyx 2.3"""
import re, string
import unicodedata
import sys, os
# Uncomment only what you need to import, please.
#from parser_tools import find_token, find_end_of, find_tokens, \
# find_token_exact, find_end_of_inset, find_end_of_layout, \
# find_token_backwards, is_in_inset, get_value, get_quoted_value, \
# del_token, check_token, get_option_value
#from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert, lyx2latex, \
# lyx2verbatim, length_in_bp, convert_info_insets
# insert_to_preamble, latex_length, revert_flex_inset, \
# revert_font_attrs, hex2ratio, str2bool
from parser_tools import find_token
####################################################################
# Private helper functions
###############################################################################
###
### Conversion and reversion routines
###
###############################################################################
def revert_microtype(document):
" Remove microtype settings. "
i = find_token(document.header, "\\use_microtype", 0)
if i == -1:
return
del document.header[i]
##
# Conversion hub
#
supported_versions = ["2.3.0", "2.3"]
convert = [
[509, []]
]
revert = [
[508, [revert_microtype]]
]
if __name__ == "__main__":
pass

View File

@ -388,6 +388,7 @@ BufferParams::BufferParams()
fonts_math[1] = "auto";
fonts_default_family = "default";
useNonTeXFonts = false;
use_microtype = false;
fonts_expert_sc = false;
fonts_old_figures = false;
fonts_sans_scale[0] = 100;
@ -771,6 +772,8 @@ string BufferParams::readToken(Lexer & lex, string const & token,
lex >> fonts_typewriter_scale[1];
} else if (token == "\\font_cjk") {
lex >> fonts_cjk;
} else if (token == "\\use_microtype") {
lex >> use_microtype;
} else if (token == "\\paragraph_separation") {
string parsep;
lex >> parsep;
@ -1139,6 +1142,7 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
if (!fonts_cjk.empty()) {
os << "\\font_cjk " << fonts_cjk << '\n';
}
os << "\\use_microtype " << convert<string>(use_microtype) << '\n';
os << "\\graphics " << graphics_driver << '\n';
os << "\\default_output_format " << default_output_format << '\n';
os << "\\output_sync " << output_sync << '\n';
@ -1411,6 +1415,9 @@ void BufferParams::validate(LaTeXFeatures & features) const
if (useNonTeXFonts && fontsMath() != "auto")
features.require("unicode-math");
if (use_microtype)
features.require("microtype");
if (!language->requires().empty())
features.require(language->requires());

View File

@ -278,6 +278,8 @@ public:
int fontsTypewriterScale() const { return fonts_typewriter_scale[useNonTeXFonts]; }
/// the font used by the CJK command
std::string fonts_cjk;
/// use LaTeX microtype package
bool use_microtype;
///
Spacing & spacing();
Spacing const & spacing() const;

View File

@ -1132,6 +1132,10 @@ string const LaTeXFeatures::getPackages() const
if (mustProvide("footmisc"))
packages << "\\PassOptionsToPackage{stable}{footmisc}\n";
if (mustProvide("microtype")){
packages << "\\usepackage{microtype}\n";
}
return packages.str();
}

View File

@ -809,6 +809,8 @@ GuiDocument::GuiDocument(GuiView & lv)
this, SLOT(change_adaptor()));
connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
this, SLOT(change_adaptor()));
connect(fontModule->microtypeCB, SIGNAL(clicked()),
this, SLOT(change_adaptor()));
connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
this, SLOT(change_adaptor()));
connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
@ -2889,6 +2891,8 @@ void GuiDocument::applyView()
bp_.fonts_cjk =
fromqstr(fontModule->cjkFontLE->text());
bp_.use_microtype = fontModule->microtypeCB->isChecked();
bp_.fonts_sans_scale[nontexfonts] = fontModule->scaleSansSB->value();
bp_.fonts_sans_scale[!nontexfonts] = fontModule->font_sf_scale;
@ -3368,6 +3372,8 @@ void GuiDocument::paramsToDialog()
toqstr(bp_.fonts_cjk));
else
fontModule->cjkFontLE->setText(QString());
fontModule->microtypeCB->setChecked(bp_.use_microtype);
fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);

View File

@ -6,47 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>407</width>
<height>285</height>
<width>541</width>
<height>319</height>
</rect>
</property>
<property name="windowTitle">
<string>FontUi</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="osFontsCB">
<property name="toolTip">
<string>Use OpenType and TrueType fonts with the fontspec package (requires XeTeX or LuaTeX)</string>
</property>
<property name="text">
<string>&amp;Use non-TeX fonts (via XeTeX/LuaTeX)</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>59</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="fontsDefaultLA">
<property name="text">
<string>&amp;Default family:</string>
</property>
<property name="buddy">
<cstring>fontsDefaultCO</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="fontsDefaultCO">
<property name="toolTip">
@ -101,6 +68,39 @@
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="osFontsCB">
<property name="toolTip">
<string>Use OpenType and TrueType fonts with the fontspec package (requires XeTeX or LuaTeX)</string>
</property>
<property name="text">
<string>&amp;Use non-TeX fonts (via XeTeX/LuaTeX)</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>59</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="fontsDefaultLA">
<property name="text">
<string>&amp;Default family:</string>
</property>
<property name="buddy">
<cstring>fontsDefaultCO</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="fontsRomanCO">
<property name="toolTip">
@ -135,6 +135,13 @@
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="fontsTypewriterCO">
<property name="toolTip">
<string>Select the typewriter (monospaced) typeface</string>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QSpinBox" name="scaleSansSB">
<property name="toolTip">
@ -158,13 +165,6 @@
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="fontsTypewriterCO">
<property name="toolTip">
<string>Select the typewriter (monospaced) typeface</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QLabel" name="scaleTypewriterLA">
<property name="text">
@ -175,6 +175,13 @@
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QComboBox" name="fontsMathCO">
<property name="toolTip">
<string>Select the math typeface</string>
</property>
</widget>
</item>
<item row="5" column="3">
<widget class="QSpinBox" name="scaleTypewriterSB">
<property name="toolTip">
@ -198,13 +205,6 @@
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QComboBox" name="fontsMathCO">
<property name="toolTip">
<string>Select the math typeface</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="cjkFontLA">
<property name="text">
@ -242,7 +242,7 @@
</property>
</widget>
</item>
<item row="10" column="1">
<item row="11" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -255,6 +255,16 @@
</property>
</spacer>
</item>
<item row="10" column="1">
<widget class="QCheckBox" name="microtypeCB">
<property name="toolTip">
<string>Activate extensions such as character protusion and font expansion via the microtype package</string>
</property>
<property name="text">
<string>Enable micr&amp;o-typographic extensions</string>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>

View File

@ -457,7 +457,8 @@ string remove_braces(string const & value)
Preamble::Preamble() : one_language(true), explicit_babel(false),
title_layout_found(false), index_number(0), h_font_cjk_set(false)
title_layout_found(false), index_number(0), h_font_cjk_set(false),
h_use_microtype(false)
{
//h_backgroundcolor;
//h_boxbgcolor;
@ -543,6 +544,7 @@ Preamble::Preamble() : one_language(true), explicit_babel(false),
h_use_geometry = "false";
h_use_default_options = "false";
h_use_hyperref = "false";
h_use_microtype = false;
h_use_refstyle = false;
h_use_packages["amsmath"] = "1";
h_use_packages["amssymb"] = "0";
@ -1013,6 +1015,13 @@ void Preamble::handle_package(Parser &p, string const & name,
h_options += ',' + join(options, ",");
}
}
else if (name == "microtype") {
//we internally support only microtype without params
if (options.empty())
h_use_microtype = true;
else
h_preamble << "\\usepackage[" << opts << "]{microtype}";
}
else if (!in_lyx_preamble) {
if (options.empty())
@ -1162,7 +1171,8 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc, string const & outfiled
<< ' ' << h_font_tt_scale[1] << '\n';
if (!h_font_cjk.empty())
os << "\\font_cjk " << h_font_cjk << '\n';
os << "\\graphics " << h_graphics << '\n'
os << "\\use_microtype " << h_use_microtype << '\n'
<< "\\graphics " << h_graphics << '\n'
<< "\\default_output_format " << h_default_output_format << "\n"
<< "\\output_sync " << h_output_sync << "\n";
if (h_output_sync == "1")

View File

@ -151,6 +151,7 @@ private:
std::string h_font_tt_scale[2];
bool h_font_cjk_set;
std::string h_font_cjk;
bool h_use_microtype;
std::string h_graphics;
std::string h_default_output_format;
std::string h_html_be_strict;

View File

@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
#define LYX_FORMAT_LYX 508 // forenr: convert parbreak to latexpar
#define LYX_FORMAT_TEX2LYX 508
#define LYX_FORMAT_LYX 509 // ps: microtype
#define LYX_FORMAT_TEX2LYX 509
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER