From: Günter Milde Date: Tue, 29 Jan 2019 11:35:12 +0000 (+0100) Subject: ctests: Dedicated test and comments for "lyx2lyx.lyx_2_4.revert_fonts". X-Git-Tag: lyx-2.4.0dev-acb2ca7b~2625 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=8060c8e488f6c5033ab7dfd4027c963ce1ce884f;p=lyx.git ctests: Dedicated test and comments for "lyx2lyx.lyx_2_4.revert_fonts". --- diff --git a/autotests/export/lyx2lyx/lyx_2_4_test.lyx b/autotests/export/lyx2lyx/lyx_2_4_test.lyx new file mode 100644 index 0000000000..a707705682 --- /dev/null +++ b/autotests/export/lyx2lyx/lyx_2_4_test.lyx @@ -0,0 +1,179 @@ +#LyX 2.4 created this file. For more info see https://www.lyx.org/ +\lyxformat 566 +\begin_document +\begin_header +\save_transient_properties true +\origin unavailable +\textclass article +\use_default_options true +\maintain_unincluded_children false +\language english +\language_package default +\inputencoding auto +\fontencoding auto +\font_roman "IBMPlexSerif" "Century Schoolbook L" +\font_sans "DejaVuSans" "DejaVu Sans" +\font_typewriter "DejaVuSansMono" "Courier 10 Pitch" +\font_math "auto" "auto" +\font_default_family default +\use_non_tex_fonts false +\font_sc false +\font_osf false +\font_sf_scale 100 100 +\font_tt_scale 100 100 +\use_microtype false +\use_dash_ligatures false +\graphics default +\default_output_format default +\output_sync 0 +\bibtex_command default +\index_command default +\float_placement class +\float_alignment class +\paperfontsize default +\spacing single +\use_hyperref false +\papersize default +\use_geometry false +\use_package amsmath 1 +\use_package amssymb 1 +\use_package cancel 1 +\use_package esint 1 +\use_package mathdots 1 +\use_package mathtools 1 +\use_package mhchem 1 +\use_package stackrel 1 +\use_package stmaryrd 1 +\use_package undertilde 1 +\cite_engine basic +\cite_engine_type default +\biblio_style plain +\use_bibtopic false +\use_indices false +\paperorientation portrait +\suppress_date false +\justification true +\use_refstyle 1 +\use_minted 0 +\index Index +\shortcut idx +\color #008000 +\end_index +\secnumdepth 3 +\tocdepth 3 +\paragraph_separation indent +\paragraph_indentation default +\is_math_indent 0 +\math_numbering_side default +\quotes_style english +\dynamic_quotes 0 +\papercolumns 1 +\papersides 1 +\paperpagestyle default +\tracking_changes false +\output_changes false +\html_math_output 0 +\html_css_as_file 0 +\html_be_strict false +\end_header + +\begin_body + +\begin_layout Description +Font +\begin_inset space ~ +\end_inset + +conversion: +\end_layout + +\begin_deeper +\begin_layout Standard +With +\begin_inset Quotes eld +\end_inset + +DejaVu .* +\begin_inset Quotes erd +\end_inset + + or +\begin_inset Quotes eld +\end_inset + +IBM Plex .* +\begin_inset Quotes erd +\end_inset + + as TeX font, +\begin_inset Quotes eld +\end_inset + +use-non-TeX fonts +\begin_inset Quotes erd +\end_inset + + +\begin_inset Quotes eld +\end_inset + +false +\begin_inset Quotes erd +\end_inset + +, and configured non-TeX fonts: +\end_layout + +\begin_layout Itemize +back conversion calls +\begin_inset Quotes eld +\end_inset + +revert_latexFonts +\begin_inset Quotes erd +\end_inset + +, which calls +\begin_inset Quotes eld +\end_inset + +revert_fonts +\begin_inset Quotes erd +\end_inset + +, which +\end_layout + +\begin_layout Itemize +ignored Quotes around a configured +\begin_inset Quotes eld +\end_inset + +non-TeX font +\begin_inset Quotes erd +\end_inset + + and +\end_layout + +\begin_layout Itemize +stripped the part after the space in the +\begin_inset Quotes eld +\end_inset + +non-TeX font +\begin_inset Quotes erd +\end_inset + + name +\end_layout + +\begin_layout Standard +\paragraph_spacing single +leading to a corrupt file. + Fixed in [c2091bec/lyxgit]. +\end_layout + +\end_deeper +\end_body +\end_document diff --git a/development/autotests/invertedTests b/development/autotests/invertedTests index 5e60d2c087..b9ce179b3e 100644 --- a/development/autotests/invertedTests +++ b/development/autotests/invertedTests @@ -60,10 +60,6 @@ export/export/latex/iconv-error-nomenclature_pdf2 check_load/templates/acmart export/templates/acmart_lyx23 -# lyx2lyx generates an invalid file when forward-converting a file with -# whitespace in the "non-tex font" setting: -export/examples/ja/multilingual_lyx.* - # Failing LyX2LyX conversions for old versions: # # "beamer" lyx2lyx fails sometimes for versions < 2.1 diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index a74cc237bd..6c0b1c707f 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -219,9 +219,9 @@ def convert_fonts(document, fm): j = find_token(document.header, ft, 0) if j != -1: val = get_value(document.header, ft, j) - vals = val.split() - vals[0] = '"' + fn + '"' - document.header[j] = ft + ' ' + ' '.join(vals) + words = val.split() # ! splits also values like '"DejaVu Sans"' + words[0] = '"' + fn + '"' + document.header[j] = ft + ' ' + ' '.join(words) def revert_fonts(document, fm, fontmap): " Revert native font definition to LaTeX " @@ -243,8 +243,8 @@ def revert_fonts(document, fm, fontmap): continue ft = mo.group(1) # 'roman', 'sans', 'typewriter', 'math' val = get_value(document.header, ft, i) - words = val.split() - font = words[0].replace('"', '') + words = val.split(' ') # ! splits also values like '"DejaVu Sans"' + font = words[0].strip('"') # TeX font name has no whitespace if not font in fm.font2pkgmap: i += 1 continue @@ -253,7 +253,7 @@ def revert_fonts(document, fm, fontmap): if not val in fontmap: fontmap[val] = [] words[0] = '"default"' - document.header[i] = ft + ' ' + ' '.join(words) + document.header[i] = ft + ' ' + ' '.join(words) if fontinfo.scaleopt != None: xval = get_value(document.header, "\\font_" + fontinfo.scaletype + "_scale", 0) mo = rscales.search(xval) @@ -600,7 +600,7 @@ def revert_floatalignment(document): alcmd = put_cmd_in_ert("\\raggedleft{}") if len(alcmd) > 0: document.body[l+1:l+1] = alcmd - i += 1 + i += 1 def revert_tuftecite(document): @@ -730,7 +730,7 @@ def revert_vcolumns(document): if vval != "": needarray = True vval += "V{\\linewidth}" - + document.body[col_line] = document.body[col_line][:-1] + " special=\"" + vval + "\">" # ERT newlines and linebreaks (since LyX < 2.4 automatically inserts parboxes # with newlines, and we do not want that) @@ -776,7 +776,7 @@ def revert_bibencoding(document): if engine in ["biblatex", "biblatex-natbib"]: biblatex = True - # Map lyx to latex encoding names + # Map lyx to latex encoding names encodings = { "utf8" : "utf8", "utf8x" : "utf8x", @@ -1328,7 +1328,7 @@ def revert_l7ninfo(document): continue arg = find_token(document.body, 'arg', i, j) argv = get_quoted_value(document.body, "arg", arg) - # remove trailing colons, menu accelerator (|...) and qt accelerator (&), while keeping literal " & " + # remove trailing colons, menu accelerator (|...) and qt accelerator (&), while keeping literal " & " argv = argv.rstrip(':').split('|')[0].replace(" & ", "").replace("&", "").replace("", " & ") document.body[i : j+1] = argv i = i + 1