On 17. des. 2010 09:37, Guenter Milde wrote:
On 2010-12-16, Helge Hafting wrote:

Here is a patch for LyX 2.0, that adds "multicol.module" and support for
it. The module provides custom insets for 2,3,4,5,6,7 and 8 columns.

Good. Thanks.

In addition to the module itself, the patch touches these 3 files:
src/LaTeXFeatures.cpp   (support for multicol.sty)

Isn't there a requires keyword in the layout syntax or am I missing
something. E.g. the enumitem module in LyX 2 starts with

#\DeclareLyXModule[enumitem.sty]{Customizable Lists (enumitem)}

I don't understand. The module works, and I wrote it using Customization.lyx as a guide. It starts with:
#\DeclareLyXModule[multicol.sty]{Multiple columns}

Which is similar do your example. "multicol.sty" is mentioned in the square brackets, and is therefore required. I have now tested that the module gets rejected when I remove multicol.sty from my texlive.



lib/doc/LaTeXConfig.lyx (document multicol.sty)
lib/Makefile.am         (makefile support for multicol.module)

I can update our existing examples of multicol documents, if this goes
in. Currently, they use ERT which is no longer needed. And maybe it
should move from "Additional" to "UserGuide" ?

Making this module showed that a couple of things are missing from the
module system, that would be really nice to have:
1. It seems to be impossible to add support for \columnbreak,
     because this is a command that doesn't take any text as
     parameter. In the LyX GUI, it should look similar to \newpage.
     Or am I missing something?

Maybe make it a dummy style similar to "-- separator --"?
but with "columnbreak" as LaTeX command?

I tried that, and will post an updated multicol.module shortly.

It sort of works, but also shows that the mechanism isn't perfect.
I get a "column break" paragraph type, which can contain text. The latex result is \columnbreak{text}. Fortunately, this cause no problems for latex, but it doesn't look good in the main window either.

Also, the user is not inserting a column break, but _changing_ the paragraph type to "column break". So unless he takes care and make an empty paragraph first, things go wrong.

The "--separator--" has the same problems, so I guess this is OK for now.


2. It'd be very useful to specify "this insets takes a
     mandatory integer parameter" and have the LyX GUI
     provide a mechanism for editing that integer. (I.e.
     an editable field in the inset label.)
     That way, we could do with a single inset for multicols
     instead of one for two columns, one for three columns and so on.
     I guess it is probably too late for that now?

LyX Styles can take an optional argument. Again citing from
enumitem.module:

An optional argument is useless here, unfortunately.

The argument to \begin{multicols}{ }
is mandatory. If it is missing, you get a compile error in the document.

I will not make a module where the user has to remmember to insert an
"optional argument" _and_ type a valid integer in it, in order to have the document compile.

If LyX gets the feature I want (possibly something as simple as
auto-inserting a non-removable "optional argument" with some default number) then I will rewrite the module to use this. (Including automatic conversion of old documents, of course.)


Style Description
        OptionalArgs          1
        Requires        enumitem
End

The optional argument can be set with the misleadingly named "short
title" menu entry.

I don't know whether it works for Insets, though.

I first tested with a multicol paragraph type, instead of an inset. It worked fine with a "short title" containing the number of columns. I then rejected this approach because it gives the user many opportunities for latex errors:
1. User can type text into the optional argument
2. User can leave the optional argument empty
3. User can type in front of the optional argument
4. User can delete the optional argument (without also
   dissolving the inset / paragraph style)
5. User can forget to insert the optional argument

Any of these will cause a latex compile failure, with the obscure message "missing number treated as zero" and of course zero columns doesn't work well either.

So this will have to wait, until the insets get a "parameter box" that only goes away when the inset is dissolved. Similiar to how "minipage" has a box of parameters. That one is perhaps too complicated to become a generic module. Simpler module insets could have a list of parameters and their types (number or text or length) with default values and perhaps some simple limits. (no limit, numeric range, or a list of valid entries.) LyX could then create a dynamic dialog when the user changes settings on such an inset. It would allow a wide range of latex constructs to be supported from modules - without any more C++ work. But such a change is for 2.1, I think.

Helge Hafting

Reply via email to