On the way towards a charstyles gui, several things still need to be done.
One is that currently char style definitions are only really possible by means 
of manual preamble definitions.

I.e., if I want to have a char style "keyword" that is roman, red and bold in 
the output, I'll need to define:

CharStyle Keyword
        LatexType             Command
        LatexName             keyword
        Font
          Family                Roman
          Color         red
          Series                bold
        EndFont
        Preamble
                \usepackage{color}
                \newcommand\keyword[1]{\textrm{\textbf{\textcolor{red}{#1}}}}
        EndPreamble
End

The "Font" param defines the screen font only, not the output font. This is 
very inconventient and will have to change in order to define char styles 
with a gui.

The attached patch is a proof-of-concept trial that changes the behaviour, so 
that the preamble definition is automatically created from the Font 
informations _if_ there exists no manual Preamble entry. The Preamble entry 
is the place for advanced and fancy stuff.

So for the above charstyle, the definition would only need to be

CharStyle Keyword
        LatexType             Command
        LatexName             keyword
        Font
          Family                Roman
          Color         red
          Series                bold
        EndFont
End

The patch works quite well, but I have a few questions:
- is LyXTextClass::readCharStyle a good place for the preamble generation?
- in order to avoid conflicts with older definitions, should we leave Font 
untouched and introduce a new "OutputFont" param? I am not sure, because 
older char style definitions did not work without a Preamble definition, and 
if one is there, it is kept.

Please comment, as I'd like to put something like this in sooner or later.

The remaining milestones on the way to a gui are:
- All used charstyles definitions will have to be included in the document, 
because currently, a document with self defined charstyles is not portable.
- currently, charstyle definitions are only possible in layout files, and thus 
bound to document classes. Additionally, we'll have to provide (1) charstyles 
that are valid for a given document only (and hence only included in the 
document) and (2) general charstyles that are selectable always (and defined 
in some general file). Only these two types can be set up with the gui (the 
user will be able to select the "scope" in the gui and change the scope of a 
given charstyle).

I don't know if I'll have enough time to do all this myself, so if somebody 
wants to help, I'll be most grateful.

Jürgen



Index: src/insets/insetcharstyle.C
===================================================================
--- src/insets/insetcharstyle.C	(Revision 15345)
+++ src/insets/insetcharstyle.C	(Arbeitskopie)
@@ -340,6 +340,8 @@ void InsetCharStyle::validate(LaTeXFeatu
 {
 	// Force inclusion of preamble snippet in layout file
 	features.require(params_.type);
+	if (params_.font.color() != LColor::ignore)
+		features.require("color");
 	InsetText::validate(features);
 }
 
Index: src/lyxtextclass.C
===================================================================
--- src/lyxtextclass.C	(Revision 15344)
+++ src/lyxtextclass.C	(Arbeitskopie)
@@ -44,6 +44,7 @@ using std::find_if;
 using std::remove_if;
 using std::string;
 using std::ostream;
+using std::ostringstream;
 
 
 namespace {
@@ -679,7 +680,17 @@ void LyXTextClass::readCharStyle(LyXLex 
 		cs.latexparam = latexparam;
 		cs.font = font;
 		cs.labelfont = labelfont;
-		cs.preamble = preamble;
+		if (preamble.empty()) {
+			ostringstream oss;
+			LyXFont tmpfont;
+			oss << "\\newcommand\\" << latexname << "[1]{";
+			font.latexWriteStartChanges(oss, tmpfont, tmpfont);
+			oss << "#1";
+			font.latexWriteEndChanges(oss, tmpfont, tmpfont);
+			oss << "}";
+			cs.preamble = oss.str();
+		} else
+			cs.preamble = preamble;
 		charstyles().push_back(cs);
 	}
 
Index: src/tex2lyx/lyxfont.h
===================================================================
--- src/tex2lyx/lyxfont.h	(Revision 15344)
+++ src/tex2lyx/lyxfont.h	(Arbeitskopie)
@@ -17,6 +17,8 @@
 #ifndef LYXFONT_H
 #define LYXFONT_H
 
+#include <iosfwd>
+
 class LyXLex;
 
 class LyXFont {
@@ -33,6 +35,12 @@ public:
 
 	LyXFont & realize(LyXFont const &) { return *this; }
 	bool resolved() const { return true; }
+
+	int latexWriteStartChanges(std::ostream &, LyXFont const &,
+				   LyXFont const &) const { return 0; }
+
+	int latexWriteEndChanges(std::ostream &, LyXFont const &,
+				 LyXFont const &) const {  return 0; }
 };
 
 #endif // NOT LYXFONT_H

Reply via email to