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

...

>>> 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.

My understanding is that this declaration line suffices to declare
the dependency on multicol.sty.

I wonder why/if it is necessary to change src/LaTeXFeatures.cpp.
I did not see changing scr/LaTeXFeatures.cpp mentioned in the
Customization guide.

>>> 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.

I see. Maybe a custom inset would be the better choice for "column
break". (Custom insets were not available at the time the
"--separator--" style was added. Unfortunately, there is no way to
"obsolete" as style with an inset.)

An inset would also allow column breaks inside a paragraph.

>>> 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.

You will need to define a wrapper in the preamble then. Something like

AddToPreamble
 \newenvironment{\lyxmulticols}[1][2]%
   {\begin{multicols}{#1}}%
   {\end{multicols}}
EndPreamble

...
        LatexName             lyxmulticols

...

> 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.

With the abovementioned wrapper, cases 2, 3, 4, and 5 should not lead
to an error.


> 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.

This would be the cleaner approach indeed. Alternatively, parameter
configuration could be done in the context menu instead of a visible box,
like in the box or branches insets.

Günter

Reply via email to