From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/10229 Path: news.gmane.org!not-for-mail From: John MacFarlane Newsgroups: gmane.text.pandoc Subject: Re: Latex tables using tabular instead of longtable Date: Mon, 30 Jun 2014 20:39:15 -0700 Message-ID: <20140701033914.GA75863@localhost.hsd1.ca.comcast.net> References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed X-Trace: ger.gmane.org 1404185980 31352 80.91.229.3 (1 Jul 2014 03:39:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 1 Jul 2014 03:39:40 +0000 (UTC) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCJZJHG45QDBB362ZCOQKGQEOTCU2LA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Tue Jul 01 05:39:32 2014 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane.org Original-Received: from mail-ve0-f192.google.com ([209.85.128.192]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1X1oum-0003ey-J6 for gtp-pandoc-discuss@m.gmane.org; Tue, 01 Jul 2014 05:39:28 +0200 Original-Received: by mail-ve0-f192.google.com with SMTP id jz11sf2009910veb.9 for ; Mon, 30 Jun 2014 20:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=from:date:to:subject:message-id:references:mime-version:in-reply-to :user-agent: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 :content-disposition; bh=/kbfwwrCT7MdC7g+HYk5OYfQJK7fEDFR+53vjk6x4gM=; b=hwnyHG7mHljLyxvgRjg/RmKZdqWlfRvuPL1GkPZTYH5dZG9XNtm6YvXvtVnTv/jxO8 xOfqumjVMOHolSwP27e1QncDAWSE2l36vwfrxZpthvHYFUmVk2rzgNNgAZhT3iXMdvXd PXkMcPh5bTisR657Wf/xmN4RfJLvVrNp1NcAuFmZCpNUSX+bpgJ3I7t61Qfg4I2dvfVg wFwWqL2eUHAHuWzK/M6EUVMn1KJ/at/pHex/Jq5hPGc/EAPEDNHHyre6PraPPR10yMjq e2Exy+gBTtTQzQuBImo20UZdR0pGuLIFn+YVaVUpZr+/jVYtk17HuopLCOpxKu7Jjgh3 dePg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:subject:message-id:references :mime-version:in-reply-to:user-agent: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:content-disposition; bh=/kbfwwrCT7MdC7g+HYk5OYfQJK7fEDFR+53vjk6x4gM=; b=dFG4JZLOy02USK9Ac0e8IpfU3RyAhvUCdYzfFpWDF05GVNLA4tXQj5t08menYXMafN 8Zu4oK5TXQTeNzdS+dMs1J/xPPnJbV2xvmfYW20EOoKc5tPiO+s5Jb+GEUjRVo1AwtCq 1/w9Qvpggyhsk7BnzjvC7ci2O/k3NwnaAi9U0B6YuEx/dU0h2OC3SV+gBqdLahkkLInZ MGRHLNOf1RBsVc9GjUtyjyP5a/29Z/+BUuYotWGjzeMlpdaVsaKq67RyiwclX/UMQRYc iIW8CtpVPbGtVDWxK1tv4NSY4lW7tpIb00wyly25ayQLyyh4yAMkBVINoXQTJn7TWU7K Q1 X-Received: by 10.50.142.104 with SMTP id rv8mr686700igb.13.1404185967519; Mon, 30 Jun 2014 20:39:27 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 10.50.136.168 with SMTP id qb8ls2039370igb.43.gmail; Mon, 30 Jun 2014 20:39:26 -0700 (PDT) X-Received: by 10.66.122.137 with SMTP id ls9mr24393598pab.17.1404185966949; Mon, 30 Jun 2014 20:39:26 -0700 (PDT) Original-Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by gmr-mx.google.com with ESMTPS id gn8si4560130pbc.0.2014.06.30.20.39.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Jun 2014 20:39:26 -0700 (PDT) Received-SPF: pass (google.com: domain of jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org designates 209.85.220.46 as permitted sender) client-ip=209.85.220.46; Original-Received: by mail-pa0-f46.google.com with SMTP id eu11so9828079pac.33 for ; Mon, 30 Jun 2014 20:39:26 -0700 (PDT) X-Gm-Message-State: ALoCoQl30AzI5KBcEt/o8WBSpaNkHRJjl8VXEen2Ctp1SMOlOKKKW6T6xx1mWUTCTpkj1mIBpln0 X-Received: by 10.68.200.133 with SMTP id js5mr57742773pbc.138.1404185966807; Mon, 30 Jun 2014 20:39:26 -0700 (PDT) Original-Received: from johnmacfarlane.net (li55-134.members.linode.com. [74.82.3.134]) by mx.google.com with ESMTPSA id is5sm30147744pbb.8.2014.06.30.20.39.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jun 2014 20:39:26 -0700 (PDT) Original-Received: by johnmacfarlane.net (Postfix, from userid 1000) id 5FAA4A307; Mon, 30 Jun 2014 23:41:05 -0400 (EDT) In-Reply-To: X-PGP-Key: http://johnmacfarlane.net/jgm.asc User-Agent: Mutt/1.5.23 (2014-03-12) X-Original-Sender: jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org designates 209.85.220.46 as permitted sender) smtp.mail=jgm-TVLZxgkOlNX2fBVCVOL8/A@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: Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-Subscribe: , List-Unsubscribe: , Content-Disposition: inline Xref: news.gmane.org gmane.text.pandoc:10229 Archived-At: Thanks for sharing. How does it deal with footnotes in tables? (That is one thing that longtable does better.) +++ Wagner Macedo [Jun 30 14 22:59 ]: > 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 [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to > [2]pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > [3]https://groups.google.com/d/msgid/pandoc-discuss/CAKGY2P%3D5brJ1YHcG > q_G_oc1Zsp6ZCXf6SDVVH9n2wUBG8uLF4A%40mail.gmail.com. > For more options, visit [4]https://groups.google.com/d/optout. > >References > > 1. mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > 2. mailto:pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > 3. https://groups.google.com/d/msgid/pandoc-discuss/CAKGY2P=5brJ1YHcGq_G_oc1Zsp6ZCXf6SDVVH9n2wUBG8uLF4A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org?utm_medium=email&utm_source=footer > 4. https://groups.google.com/d/optout