From 3a4b07528565951cfc55e571d28e2519b899c52d Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 6 Aug 2003 22:47:22 +0000 Subject: [PATCH] finish tex2lyx depth support (hopefully); more things in .cvsignore git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7515 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/.cvsignore | 8 +++- src/ChangeLog | 4 ++ src/frontends/xforms/.cvsignore | 4 ++ src/frontends/xforms/ChangeLog | 5 ++ src/tex2lyx/ChangeLog | 13 ++++++ src/tex2lyx/context.C | 82 +++++++++++++++++++++++++++------ src/tex2lyx/context.h | 9 +++- src/tex2lyx/test-structure.tex | 40 ++++++++++++++-- src/tex2lyx/text.C | 17 ++++--- 9 files changed, 155 insertions(+), 27 deletions(-) diff --git a/src/.cvsignore b/src/.cvsignore index e94535cc37..d5af05663a 100644 --- a/src/.cvsignore +++ b/src/.cvsignore @@ -1,11 +1,15 @@ config.h -version.C +config.h.in lyx +lyx-xforms +lyx-qt Makefile Makefile.in -config.h.in stamp-h stamp-h1 +version.C +version.C-tmp +stamp-version *.deps .libs a.out diff --git a/src/ChangeLog b/src/ChangeLog index dfe0a1c8e5..b4fa9dd946 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2003-08-06 Jean-Marc Lasgouttes + + * .cvsignore: add lyx-xforms, lyx-qt, version.C-tmp and stamp-version + 2003-08-05 Alfredo Braunstein * text2.C (DEPM): fix part of bug 1255 and 1256 diff --git a/src/frontends/xforms/.cvsignore b/src/frontends/xforms/.cvsignore index 077d350df8..40eb1aabc2 100644 --- a/src/frontends/xforms/.cvsignore +++ b/src/frontends/xforms/.cvsignore @@ -5,4 +5,8 @@ Makefile .libs libxforms.la lyx_forms.h +lyx_forms.h-tmp +stamp-forms lyx_xpm.h +lyx_xpm.h-tmp +stamp-xpm diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 45f7505b18..360264f2bc 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2003-08-06 Jean-Marc Lasgouttes + + * .cvsignore: add lyx_forms.h-tmp, stamp-forms, lyx_xpm.h-tmp, + stamp-xpm. + 2003-08-06 Martin Vermeer * Color.C: Kayvan's std::setw micropatch. diff --git a/src/tex2lyx/ChangeLog b/src/tex2lyx/ChangeLog index becf01bf19..c013fa708b 100644 --- a/src/tex2lyx/ChangeLog +++ b/src/tex2lyx/ChangeLog @@ -1,3 +1,16 @@ +2003-08-07 Jean-Marc Lasgouttes + + * text.C (parse_text): special handling for \item and \bibitem + macros + + * context.C (begin_layout, end_layout, begin_deeper, end_deeper): + tiny helper functions + (check_layout): + (check_end_deeper): add special handling for the case of a normal + paragraph inside a list-like environment. + + * test-structure.tex: add more stuff there + 2003-08-05 Alfredo Braunstein * context.h: compile fix diff --git a/src/tex2lyx/context.C b/src/tex2lyx/context.C index 7bb967d111..1558da7e28 100644 --- a/src/tex2lyx/context.C +++ b/src/tex2lyx/context.C @@ -9,11 +9,39 @@ using std::ostream; using std::endl; +namespace { + +void begin_layout(ostream & os, LyXLayout_ptr layout) +{ + os << "\n\\begin_layout " << layout->name() << "\n\n"; +} + + +void end_layout(ostream & os) +{ + os << "\n\\end_layout\n"; +} + + +void begin_deeper(ostream & os) +{ + os << "\n\\begin_deeper \n"; +} + + +void end_deeper(ostream & os) +{ + os << "\n\\end_deeper \n"; +} + +} + Context::Context(bool need_layout_, LyXTextClass const & textclass_, LyXLayout_ptr layout_, LyXLayout_ptr parent_layout_) : need_layout(need_layout_), need_end_layout(false), need_end_deeper(false), + has_item(false), deeper_paragraph(false), textclass(textclass_), layout(layout_), parent_layout(parent_layout_) { @@ -28,13 +56,38 @@ void Context::check_layout(ostream & os) { if (need_layout) { check_end_layout(os); - - os << "\n\\begin_layout " << layout->name() << "\n\n"; - need_layout=false; - need_end_layout = true; - if (!extra_stuff.empty()) { - os << extra_stuff; - extra_stuff.erase(); + + // are we in a list-like environment? + if (layout->isEnvironment() + && layout->latextype != LATEX_ENVIRONMENT) { + if (has_item) { + if (deeper_paragraph) { + end_deeper(os); + deeper_paragraph = false; + } + begin_layout(os, layout); + has_item = false; + need_layout=false; + need_end_layout = true; + } else { + // a standard paragraph in an + // enumeration. We have to recognize + // that this may require a begin_deeper. + if (!deeper_paragraph) + begin_deeper(os); + begin_layout(os, textclass.defaultLayout()); + need_layout=false; + need_end_layout = true; + deeper_paragraph = true; + } + } else { + begin_layout(os, layout); + need_layout=false; + need_end_layout = true; + if (!extra_stuff.empty()) { + os << extra_stuff; + extra_stuff.erase(); + } } } } @@ -42,8 +95,8 @@ void Context::check_layout(ostream & os) void Context::check_end_layout(ostream & os) { - if (need_end_layout) { - os << "\n\\end_layout\n"; + if (need_end_layout) { + end_layout(os); need_end_layout = false; } } @@ -53,11 +106,10 @@ void Context::check_deeper(ostream & os) { if (parent_layout->isEnvironment()) { if (need_end_deeper) { - // no need to have \end_deeper \begin_deeper -// FIXME: This does not work because \par already calls check_end_layout + // no need to have \end_deeper \begin_deeper need_end_deeper = false; } else { - os << "\n\\begin_deeper \n"; + begin_deeper(os); need_end_deeper = true; } } else @@ -68,9 +120,13 @@ void Context::check_deeper(ostream & os) void Context::check_end_deeper(ostream & os) { if (need_end_deeper) { - os << "\n\\end_deeper \n"; + end_deeper(os); need_end_deeper = false; } + if (deeper_paragraph) { + end_deeper(os); + deeper_paragraph = false; + } } diff --git a/src/tex2lyx/context.h b/src/tex2lyx/context.h index f7fe9671c6..663f0c135e 100644 --- a/src/tex2lyx/context.h +++ b/src/tex2lyx/context.h @@ -37,7 +37,14 @@ struct Context { // If there has been an \begin_deeper, we'll need a matching // \end_deeper bool need_end_deeper; - + // If we are in an itemize-like environment, we need an \item + // for each paragraph, otherwise this has to be a deeper + // paragraph. + bool has_item; + // we are handling a standard paragraph in an itemize-like + // environment + bool deeper_paragraph; + // The textclass of the document. Could actually be a global variable LyXTextClass const & textclass; // The layout of the current paragraph diff --git a/src/tex2lyx/test-structure.tex b/src/tex2lyx/test-structure.tex index d48767b953..3b834462da 100644 --- a/src/tex2lyx/test-structure.tex +++ b/src/tex2lyx/test-structure.tex @@ -1,18 +1,21 @@ \documentclass{article} +\newenvironment{foo}{==[}{]==} + \begin{document} This document contains all sorts of layouts we are supposed to support, along with weird nestings. +At time you will see that I use subsubsections in weird places. The +intent is just to make sure that I can include a macro-type layout +everyzhere it makes sense. A normal paragraph - -Another one \begin{equation} x = \sin y \end{equation} -with maths inside +with maths inside it. \begin{quote} An environment... @@ -55,7 +58,7 @@ Some centered stuff (does not work) \begin{quotation} An environment -\section*{with a command inside it} +\subsubsection*{with a command inside it} \end{quotation} \begin{quotation} @@ -85,4 +88,33 @@ We can also nest enumerations \item Item2 \end{enumerate} +Let's see what happens when normal paragraphs are inserted in lists: + +\begin{itemize} +\item the first item + +with some explanatory text under it + +and a second paragraph for good measure + +\subsubsection*{we can even have one as a subsubsection} + +\item the second item + +\item the third item + +\subsubsection*{and a sssection heading inside it (why not?)} +\end{itemize} + +What else? Well, we have descriptions: +\begin{description} +\item[A] first item +\item[B] second one +\end{description} + +or even bibliography +\begin{thebibliography}{9} +\bibitem{FOO} Edward Bar. \emph{The Foo Book}. (1999) +\end{thebibliography} + \end{document} diff --git a/src/tex2lyx/text.C b/src/tex2lyx/text.C index 5c4b3fba6c..f2cc658129 100644 --- a/src/tex2lyx/text.C +++ b/src/tex2lyx/text.C @@ -440,11 +440,21 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, s = parse_text(p, FLAG_BRACK_LAST, outer, newcontext); } context.need_layout = true; + context.has_item = true; context.check_layout(os); if (s.size()) os << s << ' '; } + else if (t.cs() == "bibitem") { + context.need_layout = true; + context.has_item = true; + context.check_layout(os); + os << "\\bibitem "; + os << p.getOpt(); + os << '{' << p.verbatim_item() << '}' << "\n"; + } + else if (t.cs() == "def") { string name = p.get_token().cs(); while (p.next_token().cat() != catBegin) @@ -589,13 +599,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, os << "\n\\" << t.cs() << " default \n"; } - else if (t.cs() == "bibitem") { - context.check_layout(os); - os << "\\bibitem "; - os << p.getOpt(); - os << '{' << p.verbatim_item() << '}' << "\n"; - } - else if (is_known(t.cs(), known_latex_commands)) { context.check_layout(os); begin_inset(os, "LatexCommand "); -- 2.39.2