From 151abe293e59e26bdde512c6fc0268a93012cf11 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sat, 3 Jan 2015 18:14:20 +0100 Subject: [PATCH] Parse post command argument insets (bug #8473) This is now very easy with the new InsetArgument infrastructure. --- src/tex2lyx/Makefile.am | 2 + src/tex2lyx/test/CMakeLists.txt | 1 + src/tex2lyx/test/runtests.py | 1 + src/tex2lyx/test/test-memoir.lyx.lyx | 95 ++++++++++++++++++++++++++++ src/tex2lyx/test/test-memoir.tex | 10 +++ src/tex2lyx/text.cpp | 28 ++++++-- status.21x | 2 + 7 files changed, 132 insertions(+), 7 deletions(-) create mode 100644 src/tex2lyx/test/test-memoir.lyx.lyx create mode 100644 src/tex2lyx/test/test-memoir.tex diff --git a/src/tex2lyx/Makefile.am b/src/tex2lyx/Makefile.am index 0aa887ebf4..07247a6695 100644 --- a/src/tex2lyx/Makefile.am +++ b/src/tex2lyx/Makefile.am @@ -30,6 +30,7 @@ TEST_FILES = \ test/foo.png \ test/test-insets.tex \ test/test.ltx \ + test/test-memoir.tex \ test/test-modules.tex \ test/test-refstyle-theorems.tex \ test/test-structure.tex \ @@ -47,6 +48,7 @@ TEST_RESULTS = \ test/Dummy~Document.lyx.lyx \ test/test-insets.lyx.lyx \ test/test.lyx.lyx \ + test/test-memoir.lyx.lyx \ test/test-modules.lyx.lyx \ test/test-refstyle-theorems.lyx.lyx \ test/test-structure.lyx.lyx \ diff --git a/src/tex2lyx/test/CMakeLists.txt b/src/tex2lyx/test/CMakeLists.txt index ea79c2c6f3..e41639a140 100644 --- a/src/tex2lyx/test/CMakeLists.txt +++ b/src/tex2lyx/test/CMakeLists.txt @@ -15,6 +15,7 @@ set(_tex_tests test.ltx CJK.tex CJKutf8.tex test-insets.tex + test-memoir.tex test-modules.tex test-refstyle-theorems.tex test-structure.tex diff --git a/src/tex2lyx/test/runtests.py b/src/tex2lyx/test/runtests.py index 71f615e8be..499410644b 100755 --- a/src/tex2lyx/test/runtests.py +++ b/src/tex2lyx/test/runtests.py @@ -75,6 +75,7 @@ def main(argv): 'CJK.tex', \ 'CJKutf8.tex', \ 'test-insets.tex', \ + 'test-memoir.tex', \ 'test-modules.tex', \ 'test-refstyle-theorems.tex', \ 'test-structure.tex', \ diff --git a/src/tex2lyx/test/test-memoir.lyx.lyx b/src/tex2lyx/test/test-memoir.lyx.lyx new file mode 100644 index 0000000000..7dc5af7efd --- /dev/null +++ b/src/tex2lyx/test/test-memoir.lyx.lyx @@ -0,0 +1,95 @@ +#LyX file created by tex2lyx 2.1 +\lyxformat 474 +\begin_document +\begin_header +\textclass memoir +\begin_preamble + + +\usepackage{babel} + +\end_preamble +\options oldfontcommands +\use_default_options false +\maintain_unincluded_children false +\language english +\language_package default +\inputencoding iso8859-15 +\fontencoding T1 +\font_roman default +\font_sans default +\font_typewriter default +\font_math auto +\font_default_family default +\use_non_tex_fonts false +\font_sc false +\font_osf false +\font_sf_scale 100 +\font_tt_scale 100 +\graphics default +\default_output_format default +\output_sync 0 +\bibtex_command default +\index_command default +\paperfontsize default +\spacing single +\use_hyperref false +\papersize default +\use_geometry false +\use_package amsmath 1 +\use_package amssymb 0 +\use_package cancel 0 +\use_package esint 1 +\use_package mathdots 0 +\use_package mathtools 0 +\use_package mhchem 0 +\use_package stackrel 0 +\use_package stmaryrd 0 +\use_package undertilde 0 +\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 0 +\index Index +\shortcut idx +\color #008000 +\end_index +\secnumdepth 3 +\tocdepth 3 +\paragraph_separation indent +\paragraph_indentation default +\quotes_language english +\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 Epigraph +epigraph +\begin_inset Argument post:1 +status collapsed + + +\begin_layout Standard +source +\end_layout + +\end_inset + + +\end_layout + +\end_body +\end_document diff --git a/src/tex2lyx/test/test-memoir.tex b/src/tex2lyx/test/test-memoir.tex new file mode 100644 index 0000000000..3d402b95e5 --- /dev/null +++ b/src/tex2lyx/test/test-memoir.tex @@ -0,0 +1,10 @@ +\documentclass[oneside,english,oldfontcommands]{memoir} +\usepackage[T1]{fontenc} +\usepackage[latin9]{inputenc} + +\usepackage{babel} +\begin{document} + +\epigraph{epigraph}{source} + +\end{document} diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 35b116ef1b..87af33c36a 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -47,7 +47,7 @@ namespace lyx { namespace { -void output_arguments(ostream &, Parser &, bool, bool, Context &, +void output_arguments(ostream &, Parser &, bool, bool, bool, Context &, Layout::LaTeXArgMap const &); } @@ -64,8 +64,12 @@ void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer, else newcontext.font = context.font; if (layout) - output_arguments(os, p, outer, false, newcontext, layout->latexargs()); + output_arguments(os, p, outer, false, false, newcontext, + layout->latexargs()); parse_text(p, os, flags, outer, newcontext); + if (layout) + output_arguments(os, p, outer, false, true, newcontext, + layout->postcommandargs()); newcontext.check_end_layout(os); } @@ -623,7 +627,7 @@ void skip_spaces_braces(Parser & p, bool keepws = false) } -void output_arguments(ostream & os, Parser & p, bool outer, bool need_layout, +void output_arguments(ostream & os, Parser & p, bool outer, bool need_layout, bool post, Context & context, Layout::LaTeXArgMap const & latexargs) { if (need_layout) { @@ -646,6 +650,8 @@ void output_arguments(ostream & os, Parser & p, bool outer, bool need_layout, need_layout = false; } begin_inset(os, "Argument "); + if (post) + os << "post:"; os << i << "\nstatus collapsed\n\n"; parse_text_in_inset(p, os, FLAG_BRACE_LAST, outer, context); end_inset(os); @@ -659,6 +665,8 @@ void output_arguments(ostream & os, Parser & p, bool outer, bool need_layout, need_layout = false; } begin_inset(os, "Argument "); + if (post) + os << "post:"; os << i << "\nstatus collapsed\n\n"; parse_text_in_inset(p, os, FLAG_BRACK_LAST, outer, context); end_inset(os); @@ -691,8 +699,11 @@ void output_command_layout(ostream & os, Parser & p, bool outer, context.need_end_deeper = true; } context.check_deeper(os); - output_arguments(os, p, outer, true, context, context.layout->latexargs()); + output_arguments(os, p, outer, true, false, context, + context.layout->latexargs()); parse_text(p, os, FLAG_ITEM, outer, context); + output_arguments(os, p, outer, false, true, context, + context.layout->postcommandargs()); context.check_end_layout(os); if (parent_context.deeper_paragraph) { // We must suppress the "end deeper" because we @@ -1682,10 +1693,13 @@ void parse_environment(Parser & p, ostream & os, bool outer, // Unfortunately LyX can't handle arguments of list arguments (bug 7468): // It is impossible to place anything after the environment name, // but before the first \\item. - if (context.layout->latextype == LATEX_ENVIRONMENT) { - output_arguments(os, p, outer, false, context, context.layout->latexargs()); - } + if (context.layout->latextype == LATEX_ENVIRONMENT) + output_arguments(os, p, outer, false, false, context, + context.layout->latexargs()); parse_text(p, os, FLAG_END, outer, context); + if (context.layout->latextype == LATEX_ENVIRONMENT) + output_arguments(os, p, outer, false, true, context, + context.layout->postcommandargs()); context.check_end_layout(os); if (parent_context.deeper_paragraph) { // We must suppress the "end deeper" because we diff --git a/status.21x b/status.21x index fc2fc48664..37416ebbfa 100644 --- a/status.21x +++ b/status.21x @@ -188,6 +188,8 @@ What's new - Fix misparsing of \textgreek without polyglossia (bug 8553). +- Parse post command argument insets (bug 8473). + * ADVANCED FIND AND REPLACE -- 2.39.5