From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/10228 Path: news.gmane.org!not-for-mail From: Wagner Macedo Newsgroups: gmane.text.pandoc Subject: Latex tables using tabular instead of longtable Date: Mon, 30 Jun 2014 22:59:05 -0300 Message-ID: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c2c91409424404fd182068 X-Trace: ger.gmane.org 1404179972 27418 80.91.229.3 (1 Jul 2014 01:59:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 1 Jul 2014 01:59:32 +0000 (UTC) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCO6LFVV4YMRB7NLZCOQKGQEHM44EVI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Tue Jul 01 03:59:27 2014 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane.org Original-Received: from mail-qc0-f191.google.com ([209.85.216.191]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1X1nLy-0002Ws-KV for gtp-pandoc-discuss@m.gmane.org; Tue, 01 Jul 2014 03:59:26 +0200 Original-Received: by mail-qc0-f191.google.com with SMTP id l6sf1936233qcy.28 for ; Mon, 30 Jun 2014 18:59:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:from:date:message-id:subject:to:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:sender:list-subscribe :list-unsubscribe:content-type; bh=sPjODvQOyj0meY5ugp1/+PbcBbQFmvJei6Ag79aFm5U=; b=s6aOmH+yN7VwyK4wPuOzsoeR3a857pFxCs8NLd9EvLZpj0RyqT+8WIFSPgpraagWs8 aq/n38xbDixNGv+vgezOrXnWCDyQUs/T/LxJkQVAVLqlDL2/UkvsRoOBVz+nsMIopS5K 8x9hawt2KpXUlNM2QP/PwdyEtvjtod/NqTeIb4vtJn+odTpe7G9OjNHw4CVDBqa80zm6 WlT+6zcRyQYRY0iCINjPkB9MKtvt/9R1AzM4Bo68qx5miHb1vkEiqxLpRX1bvxCTFmsU tUx3O/Ltv7qXwtCVpCXMbDaKwQrVMX0Agp8kmihyieSM2YKhQ6v5BhBO+bxqA7AZ0WYq vP1g== X-Received: by 10.140.36.232 with SMTP id p95mr107705qgp.6.1404179965880; Mon, 30 Jun 2014 18:59:25 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 10.140.18.242 with SMTP id 105ls1684572qgf.83.gmail; Mon, 30 Jun 2014 18:59:25 -0700 (PDT) X-Received: by 10.58.160.72 with SMTP id xi8mr25120490veb.15.1404179965441; Mon, 30 Jun 2014 18:59:25 -0700 (PDT) Original-Received: from mail-ve0-x22d.google.com (mail-ve0-x22d.google.com [2607:f8b0:400c:c01::22d]) by gmr-mx.google.com with ESMTPS id fh2si967847vdb.3.2014.06.30.18.59.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Jun 2014 18:59:25 -0700 (PDT) Received-SPF: pass (google.com: domain of wagnerluis1982-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:400c:c01::22d as permitted sender) client-ip=2607:f8b0:400c:c01::22d; Original-Received: by mail-ve0-f173.google.com with SMTP id db11so8909650veb.4 for ; Mon, 30 Jun 2014 18:59:25 -0700 (PDT) X-Received: by 10.220.177.133 with SMTP id bi5mr35762550vcb.26.1404179965358; Mon, 30 Jun 2014 18:59:25 -0700 (PDT) Original-Received: by 10.220.111.142 with HTTP; Mon, 30 Jun 2014 18:59:05 -0700 (PDT) X-Original-Sender: wagnerluis1982-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of wagnerluis1982-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:400c:c01::22d as permitted sender) smtp.mail=wagnerluis1982-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dkim=pass header.i=@gmail.com; dmarc=pass (p=NONE dis=NONE) header.from=gmail.com 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: Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-Subscribe: , List-Unsubscribe: , Xref: news.gmane.org gmane.text.pandoc:10228 Archived-At: --001a11c2c91409424404fd182068 Content-Type: text/plain; charset=UTF-8 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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAKGY2P%3D5brJ1YHcGq_G_oc1Zsp6ZCXf6SDVVH9n2wUBG8uLF4A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout. --001a11c2c91409424404fd182068 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
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 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 com= mon to my writings.

filter.py
import pandocfilters as pf

def =
latex(s):
    return<=
/span> pf.RawBlock('la=
tex', s)

def =
inlatex(s):
    return<=
/span> pf.RawInline('l=
atex', s)

def =
tbl_caption(s):
    return<=
/span> pf.Para([inlatex(r&=
#39;\caption{')] + s + [inlatex('}')])

def =
tbl_alignment(s):
    aligns =3D {
        "AlignDefault=
": 'l'=
,
        =
"AlignLeft": 'l',
        =
"AlignCenter": 'c',
        =
"AlignRight": 'r',
    }
    return<=
/span> ''.j=
oin([aligns[e['t'<=
/span>]] fo=
r e in s])

def =
tbl_headers(s):
    result =3D 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<=
/span> pf.Para(result)

def =
tbl_contents(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<=
/span> pf.Para(result)

def =
do_filter(k, v, f, m):
    if k =3D=3D "Table&qu=
ot;:
        ret=
urn [latex(r'\b=
egin{table}[ht]' '\n' r'=
\centering' =
9;\n'),
                tbl_caption(v[0]),
                latex(r=
9;\begin{tabular}{@{}%s@{=
}}' % tb=
l_alignment(v[1]) +
                      (=
9;\n' r'\toprule')),
                tbl_headers(v[3]),
                tbl_contents(v[4]),
                latex(r=
9;\bottomrule' =
'\n' r'\end{tabular}'),
                latex(r=
9;\end{table}<=
span class=3D"" style=3D"color:rgb(64,112,160)">')]


if <=
span class=3D"" style=3D"color:rgb(0,112,32)">__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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://group= s.google.com/d/msgid/pandoc-discuss/CAKGY2P%3D5brJ1YHcGq_G_oc1Zsp6ZCXf6SDVV= H9n2wUBG8uLF4A%40mail.gmail.com.
For more options, visit http= s://groups.google.com/d/optout.
--001a11c2c91409424404fd182068--