DocBook: implement CALS tables

Richard Kimberly Heck rikiheck at lyx.org
Mon Jul 13 03:09:48 UTC 2020


On 7/12/20 9:41 PM, Thibaut Cuvelier wrote:
> Dear list,
>
> Here is a patch to improve DocBook support by allowing the user to
> choose the way they want tables to be output (i.e. either HTML or
> CALS, right now). This amounts to including a switch in the GUI (did I
> do this right? the diff for the .ui file is quite large for what it does)

That is pretty typical. QtDesigner seems to write different styles with
every release.


> and, depending on the value, output in HTML or CALS.

Seems worth supporting.


> I preferred to use an enum and a dropdown for this parameter, as using
> a simple checkbox would seem to be awkward (it's a choice between two
> mutually exclusive options — you *have to* pick one —, it's not
> something you enable or not).

Radio buttons are another option. They also force a choice. With more
than three or four, it gets ugly, but with two it might be more obvious,
and there will always be a default setting.


> Apart from the UI part, I feel rather unsure about the implementation
> of row separators: I don't really understand the LaTeX code that
> outputs \toprule, \midrule, \bottomrule, or \hline… It sits in
> Tabular::TeXTopHLine andTabular::TeXBottomHLine. Or can I just
> copy-paste the code that sets nset, have_trims, and the others, and
> have the same logic? (It just looks too cumbersome…)

I do not know this code at all well. I am not sure it works properly in
XHTML output. If you can get it to work, then that's probably good
enough. Jürgen may have some ideas, as he does know this code.


> From 07f989abdbcf531ab3b118fa9e54978728f25941 Mon Sep 17 00:00:00 2001
> From: Thibaut Cuvelier <tcuvelier at lyx.org>
> Date: Mon, 13 Jul 2020 03:31:48 +0200
> Subject: [PATCH] Add support for CALS tables in DocBook.
>
> Also includes LYX_ALIGN_DECIMAL.

I know it's a PITA, but if you can separate this out without too much
trouble.... We try our best to follow this kind of rule. It makes
finding bugs easier, especially when bisecting (though it can increase
the number of bisects...). It also makes code review simpler.


> diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
> index 5c5241e069..611f30d354 100644
> --- a/src/insets/InsetTabular.cpp
> +++ b/src/insets/InsetTabular.cpp
> @@ -3572,35 +3664,57 @@ void Tabular::docbook(XMLStream & xs,
> OutputParams const & runparams) const
>          xs << xml::CR();
>      }
>  
> -    // "Formal" tables have a caption and use the tag <table>; the
> distinction with <informaltable> is done outside.
> +    // "Formal" tables have a title and use the tag <table>; the
> distinction with <informaltable> is done outside.
> +    // HTML has the caption first with titles forbidden, and CALS has
> a title first.
>      if (haveLTCaption()) {
> -        xs << xml::StartTag("caption");
> +        std::string tag = ((buffer().params().docbook_table_output)
> == BufferParams::HTMLTable) ? "caption" : "title";
> +
> +        xs << xml::StartTag(tag);
>          for (row_type r = 0; r < nrows(); ++r)
>              if (row_info[r].caption)
>                  docbookRow(xs, r, runparams);
> -        xs << xml::EndTag("caption");
> +        xs << xml::EndTag(tag);
>          xs << xml::CR();
>      }
>  
> -    // output header info
> +    // CALS header: describe all columns in this table. For names,
> take 'c' then the ID of the column.
> +    // Start at one, as is customary with CALS!
> +    if (buffer().params().docbook_table_output ==
> BufferParams::CALSTable) {
> +        for (col_type c = 0; c < ncols(); ++c) {
> +            std::stringstream attr;
> +            attr << "colnum='" << (c + 1) << "' ";
> +            attr << "colname='c" << (c + 1) << "' ";
> +            Length const cwidth = column_info[c].p_width;
> +            if (!cwidth.zero())
> +                attr << "colwidth='" << cwidth.asHTMLString() << "' ";
> +            attr << "rowheader='norowheader'"; // Last attribute,
> hence no space at the end.
> +
> +            xs << xml::CompTag("colspec", attr.str());
> +            xs << xml::CR();
> +        }
> +    }
> +
> +    // Output the header of the table. For both HTML and CALS, this
> is surrounded by a thead.
>      bool const havefirsthead = haveLTFirstHead(false);
>      // if we have a first head, then we are going to ignore the
>      // headers for the additional pages, since there aren't any
> -    // in XHTML. this test accomplishes that.
> +    // in DocBook. this test accomplishes that.
>      bool const havehead = !havefirsthead && haveLTHead(false);
>      if (havehead || havefirsthead) {
>          xs << xml::StartTag("thead") << xml::CR();
>          for (row_type r = 0; r < nrows(); ++r) {
>              if (((havefirsthead && row_info[r].endfirsthead) ||
> -                 (havehead && row_info[r].endhead)) &&
> -                !row_info[r].caption) {
> -                docbookRow(xs, r, runparams, true);
> +                 (havehead && row_info[r].endhead)) &&
> +                !row_info[r].caption) {
> +                docbookRow(xs, r, runparams, true); // TODO: HTML vs CALS
>              }
>          }
>          xs << xml::EndTag("thead");
>          xs << xml::CR();
>      }
> -    // output footer info
> +
> +    // Output the header of the table. For both HTML and CALS, this
> is surrounded by a tfoot and output just after
> +    // the header (and before the body).

Footer, I take it. (C&P error?)


> diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp

Thanks for thinking about the tex2lyx part! I'd also do this as a
separate commit.

Riki


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lyx.org/pipermail/lyx-devel/attachments/20200712/11b54837/attachment-0001.html>


More information about the lyx-devel mailing list