From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/25182 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Leon Bartz Newsgroups: gmane.text.pandoc Subject: Re: Latex tables using tabular instead of longtable Date: Wed, 13 May 2020 11:16:59 -0700 (PDT) Message-ID: <112d046a-8566-4d63-8af2-8bb001a5a1ce@googlegroups.com> References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_2870_724125441.1589393819625" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="90815"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDKNZ3HTZ4MRBHXT6D2QKGQEFCY4VIA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed May 13 20:17:07 2020 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ot1-f59.google.com ([209.85.210.59]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jYvwH-000NQG-D6 for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 13 May 2020 20:17:05 +0200 Original-Received: by mail-ot1-f59.google.com with SMTP id v8sf226824otj.5 for ; Wed, 13 May 2020 11:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:date:from:to:message-id:in-reply-to:references:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=5yImxUVCZFvU+gUdmGjKTXjHd6CTwQIr2RVlfGXFlyQ=; b=IH4CLLEq8hfSYUQLh9iigGtokzCH7pirYPCC0YVeqoNf+5THHd36y/0z2WFWJYnj4R MpAf4HHrte0qGqGvWT+oU3vOC+gWKfdPHiHw2XXzFjIMKMNjMFQcLSiGV2SFJrd15w0t x9WnUFeiGzb+QjjPKv8MHIGCHRaAbwZfXpDynlBjfTF3ozmr6aRerplQxiQdc0FUvNne SnZbV32nYhmdXfVEChkz/4wElfEH7PBjOS5YUz64w6N8+v9p7MJVovbAXfEl7mclqR5C kQyZBpuZaVfkkXjFkg6QzfkEpr7BVKkH9JTFK7z4DiZP9DgqWr3Ctk2ZOF7PztLbOAsu CRpw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:message-id:in-reply-to:references:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=5yImxUVCZFvU+gUdmGjKTXjHd6CTwQIr2RVlfGXFlyQ=; b=GJvHwCrtxcFEd3c+T/KdAhuG9nzxicIM+Y6TeXVNsGTTTy7X1HF05gVqyceUCH1Xt8 DR3OhF0uGzUrBldNPgZqktOoRbJ0abAp+osP3rkxHMAlUj3qnxaVGCf9TkNtgEbaAqB5 QfPGvYvfjX18FFA9/I89fo+bX4nJTbOYrnpgCpXe+MRhaAsFHOOonB7dcqQoRGcDjpwt hq5gvuQ2+uXoaIwt+w1Nss5Y0PwArmd4DlH/DHxGOSSJpM2lEXnnySLMKpyDLy39jNkH 3Vl7N0RdsNuRdtY2Sl8wssyz6L6hEbJOrcDBuyAwjsUsVO64V41z+LMSx3ON8WEWjsZc Mqgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:date:from:to:message-id:in-reply-to :references:subject:mime-version:x-original-sender:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=5yImxUVCZFvU+gUdmGjKTXjHd6CTwQIr2RVlfGXFlyQ=; b=mScNwWfSCYHtTPwkBh2jal+tuL2TABNb1sdK6XJCrqfGIDYVJej0S3CYU93EbfaVfm kK/KP8+VZSrBbBTyJFgpQ9SODAIBhiVhBkgjcGe6SpRCFsgg14nMYCq2DFjC8CCBMB2E UPfntbUaLL4/UezoGRqVcK8FChLDNL7+oA6eXftO11Uus+oK14I+KQzWMIQfBxEOW/92 MdXeDyOgPAAhDJBw25v6s8nN5wJ/geCDOcvzs5juLRKvb7YiAtXoAZRC3gD9IwjomswS NEOuVC63iy48t/hbmqZashQYePAxZCBFA/srWHNpsZj6YyQB7xeyIt7iwIDVro9vSY0G poew== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM530ZZReQXZq7wg7q3wRHUa1e91S2qkC88thMPwV0qiIs7wSmFhuK lfnhfhp+29itpU6gwbuv/HU= X-Google-Smtp-Source: ABdhPJzMye7BAGq8HYqrN2E1IqnAB5i6iBdZqQt/o1OBRkbZTzTi1lgSCq9PJ4b7u6LBuGsXqL4xmQ== X-Received: by 2002:a4a:e0d1:: with SMTP id e17mr541999oot.1.1589393824343; Wed, 13 May 2020 11:17:04 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6830:3147:: with SMTP id c7ls27130ots.7.gmail; Wed, 13 May 2020 11:17:02 -0700 (PDT) X-Received: by 2002:a9d:784b:: with SMTP id c11mr618485otm.28.1589393821869; Wed, 13 May 2020 11:17:01 -0700 (PDT) In-Reply-To: X-Original-Sender: leonbartz1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.io gmane.text.pandoc:25182 Archived-At: ------=_Part_2870_724125441.1589393819625 Content-Type: multipart/alternative; boundary="----=_Part_2871_1315202858.1589393819626" ------=_Part_2871_1315202858.1589393819626 Content-Type: text/plain; charset="UTF-8" Hi, the script does not Work with the example below. Can somebody please help ? Tanks > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
1234
567
8912
345
> > Am Dienstag, 1. Juli 2014 03:59:26 UTC+2 schrieb Wagner Macedo: > > Hello guys. > > I don't like how *longtable* handle with tables, spanning across pages > without needing, so I took advantage of the filtering mechanism and I did a > filter in python to generate the tables in a more traditional way (in the > sense of Latex) and I'm sharing with you below. > > Please make suggestions, I did the things a few hardcoded because I didn't > see other way. > > To understand what the filter do, let's say I have a file with the > following table: > > *test.mkd* > > Code Name > ------ ------ > 1 Pandoc > 2 Latex > 3 Writer > > Table: My *best* tools > > The normal generated latex code would be > > *test-longtable.tex* > > \begin{longtable}[c]{@{}cl@{}} > \toprule\addlinespace > Code & Name > \\\addlinespace > \midrule\endhead > 1 & Pandoc > \\\addlinespace > 2 & Latex > \\\addlinespace > 3 & Writer > \\\addlinespace > \bottomrule > \addlinespace > \caption{My \emph{best} tools} > \end{longtable} > > But using the filter, the latex code will be > > *test-tabular.tex* > > \begin{table}[ht] > > \caption{My \emph{best} tools} > > \begin{tabular}{@{}cl@{}} > \toprule > > Code & Name \\\midrule > > 1 & Pandoc \\ > 2 & Latex \\ > 3 & Writer \\ > > \bottomrule > \end{tabular} > > \end{table} > > Note I put \caption above as is more common to my writings. > > *filter.py* > > import pandocfilters as pf > def latex(s): > return pf.RawBlock('latex', s) > def inlatex(s): > return pf.RawInline('latex', s) > def tbl_caption(s): > return pf.Para([inlatex(r'\caption{')] + s + [inlatex('}')]) > def tbl_alignment(s): > aligns = { > "AlignDefault": 'l', > "AlignLeft": 'l', > "AlignCenter": 'c', > "AlignRight": 'r', > } > return ''.join([aligns[e['t']] for e in s]) > def tbl_headers(s): > result = s[0][0]['c'][:] > for i in range(1, len(s)): > result.append(inlatex(' & ')) > result.extend(s[i][0]['c']) > result.append(inlatex(r' \\\midrule')) > return pf.Para(result) > def tbl_contents(s): > result = [] > for row in s: > para = [] > for col in row: > para.extend(col[0]['c']) > para.append(inlatex(' & ')) > result.extend(para) > result[-1] = inlatex(r' \\' '\n') > return pf.Para(result) > def do_filter(k, v, f, m): > if k == "Table": > return [latex(r'\begin{table}[ht]' '\n' r'\centering' '\n'), > tbl_caption(v[0]), > latex(r'\begin{tabular}{@{}%s@{}}' % tbl_alignment(v[1]) + > ('\n' r'\toprule')), > tbl_headers(v[3]), > tbl_contents(v[4]), > latex(r'\bottomrule' '\n' r'\end{tabular}'), > latex(r'\end{table}')] > > if __name__ == "__main__": > pf.toJSONFilter(do_filter) > > -- > Wagner Macedo > -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/112d046a-8566-4d63-8af2-8bb001a5a1ce%40googlegroups.com. ------=_Part_2871_1315202858.1589393819626 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi, the script does not Work with the example below. = Can somebody please help ? Tanks
<table>
<thead>
<tr>
<th>1</th>
<= /span><th>2</th>
<th>3</th>
<= blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, 2= 04, 204); padding-left: 1ex;"> <= ;th>4</th>
</tr>
</thead>
&l= t;tbody>
<tr>
= <td>5</td>
= <td>6</td>
<td>7</td>
<td&g= t;</td>
</tr>
<tr>
<td>= 8</td>
<td>9</td>
<td>1</td&= gt;
<td>2</td>
</tr>
<tr&g= t;
<td>3</td>
<td>4</td>
<td>5</td>
<td></td>
</tr= >
</tbody>
<= /table>=C2=A0
Am Dienstag, 1. Juli 2014 03:59:2= 6 UTC+2 schrieb Wagner Macedo:
=
Hello guys.

I don't like= how longtable handle with tables, spanning across pages without nee= ding, so I took advantage of the filtering mechanism and I did a filter in = python to generate the tables in a more traditional way (in the sense of La= tex) and I'm sharing with you below.

Please make suggestions, I did the things a few hardcod= ed because I didn't see other way.

To understa= nd what the filter do, let's say I have a file with the following table= :

test.mkd
Code   Name
------  ------
  1     Pandoc
  2     Latex
  3     Writer

Table: My *best* tools
The normal generated latex co= de would be

test-longtable.tex
\begin{longtable}[c]{@{}cl@{}} \toprule\addlinespace Code & Name \\\addlinespace \midrule\endhead 1 & Pandoc \\\addlinespace 2 & Latex \\\addlinespace 3 & Writer \\\addlinespace \bottomrule \addlinespace \caption{My \emph{best} tools} \end{longtable}
But using t=
he filter, the latex code will be
test-tabular.tex
\begin{table}[ht]

\caption{My \emph{best} tools}

\begin{tabular}{@{}cl@{}}
\toprule

Code & Name \\\midrule

1 & Pandoc \\
2 & Latex \\
3 & Writer \\

\bottomrule
\end{tabular}

\end{table}
Note I put \caption above as is more com= mon to my writings.

filter.py
import<=
/span> pandocfilters as pf

def latex(s):
    return pf.R=
awBlock('latex', s)

def inlatex(s):
    return pf.R=
awInline('latex', s)

def tbl_caption=
(s):
    return pf.P=
ara([inlatex(r'\caption{')] + s + [inlatex('}'=
)])

def tbl_alignme=
nt(s):
    aligns =3D {
        "AlignDefault": 'l',
        "Align=
Left": 'l'=
,
        "Align=
Center": 'c',
        "Align=
Right": 'r',
    }
    return ''.join([aligns[e['t']] for e in s])

def tbl_headers=
(s):
    result =3D s[0][0]['c'][:]
    for i in range(1, len(s)):
        result.append(inlatex(' &=
amp; '))
        result.extend(s[i][0][=
'c'])
    result.append(inlatex(r' \\\m=
idrule'))
    return pf.P=
ara(result)

def tbl_content=
s(s):
    result =3D []
    for row in =
s:
        para =3D []
        for col=
 in row:
            para.extend(col[0]=
['c'])
            para.append(inlatex('=
 & '))
        result.extend(para)
        result[-1] =3D inlatex=
(r' \\' '\=
n')
    return pf.P=
ara(result)

def do_filter(k=
, v, f, m):
    if k =3D=3D=
 "Table":
        return =
[latex(r'\begin{table}[ht]' '\n' r'\centering'=
; '\n'<=
/span>),
                tbl_caption(v[0]),
                latex(r'\begin{tabular}{@{}%s=
@{}}' % =
tbl_alignment(v[1]) +
                      ('\n' r'\toprule&#=
39;)),
                tbl_headers(v[3]),
                tbl_contents(v[4]),
                latex(r'\bottomru=
le' '\n=
' r'\end{tabular}'),
                latex(r'\end{table}')]


if __name__ =3D=3D "__main__":
    pf.toJSONFilter(do_filter)
--
Wagner Macedo

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/= msgid/pandoc-discuss/112d046a-8566-4d63-8af2-8bb001a5a1ce%40googlegroups.co= m.
------=_Part_2871_1315202858.1589393819626-- ------=_Part_2870_724125441.1589393819625--