Ok I’ve now realized that the 2 approaches mentioned so far are not going to
work:
* The first one mixes content and styling and is complex for the user to use
* The second one is actually very limited and doesn’t allow full control of the
LaTeX markup used
So I’ve been thinking about a new approach that would both separate the content
from the styling and at the same time allow full control of the produced LaTeX
for perfect typesetting.
The idea is:
* Don’t provide a Listener for LaTeX in XWiki and instead only provide a
BlockRenderer (i.e. no streaming generation of content). That’s the limitation.
* For each XWiki Block object, provide a default LaTeX template that is called
to generate the LaTeX content.
* Allow Velocity in the LaTeX template and provide velocity tools + bind the
passed Block to the $block variable.
* For example for TableBlock:
---- start here ----
## Compute the number of columns
#set ($firstRowBlock = $blocks.getChildren().get(0))
#set ($columnSize = $firstRowBlock.getChildren().size())
#set ($tableSpec = "${stringtool.repeat("l|", $columnSize - 1)}l"
\begin{tabular}{${tableSpec}}
## For all rows
#foreach ($rowBlock in $blocks.getChildren())
## for all cells
#foreach ($cellBlock in $rowBlock.getChildren())
#processTemplates($cellBlock.getChildren()) &
## TODO: if last cell then output ""\\"
#end
## TODO: if last row then don't output \hline
\hline
#end
\end{tabular}
---- end here -----
* Users will be able to override the default templates for each Block
* If the user wants to use a special template for a specific Block, define it
using a “tex-template” parameter. For example:
(% tex-template=‘customTemplateForThisTable’ %)
|=A|=B
|a|b
* A template can set any variable in the VelocityContext so that templates
downstream can access them.
There are still details to iron out ofc.
WDYT?
Thanks
-Vincent
> On 14 Feb 2018, at 21:01, Vincent Massol <[email protected]> wrote:
>
> Hi devs,
>
> I’m currently working on improving our TeX renderer (which is really a POC
> ATM), in an effort to see if it could be used to generate nice PDF exports
> (you generate LaTeX and then you convert to PDF).
>
> The main issue is that LaTeX doesn’t have any technology for applying style
> to it (like CSS has for HTML). In addition I wasn’t able to find any good
> HTML+CSS to TeX converter (as we have for PDFs with XSLT+FOP).
>
> So right now my idea is to implement some default behavior in the Tex
> Renderer (that could be configured globally in xwiki.properties and/or in the
> Admin UI) and give the ability to override specifically in the content.
>
> For example, imagine that you need to decide how to position table column
> content (left, centered, right) or whether the rows and/or columns of your
> table have vertical and horizontal lines (or other configs, autowrap, etc).
>
> The idea is that the Tex Renderer would support some custom tex-specific
> parameters. For example:
>
> (% tex-table-spec=“c | c | c" tex-table-floating="true"
> tex-table-caption="caption" %)
> |=A|=B
> (% tex-table-row-ending="\hline" %)|a|b
>
> (by default the table spec would be left aligned with vertical lines, and
> rows would be separated by horizontal lines).
>
> If you have some comments or ideas, please let me know.
>
> Inventing a CSS-like mechanism would just be too hard to implement IMO.
>
> Thanks
> -Vincent
>
> PS: If you want to see table options in LaTeX, see
> https://en.wikibooks.org/wiki/LaTeX/Tables
>