From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/18173 Path: news.gmane.org!.POSTED!not-for-mail From: Jan Hermes Newsgroups: gmane.text.pandoc Subject: Re: Latex tables using tabular instead of longtable Date: Thu, 14 Sep 2017 04:44:36 -0700 (PDT) Message-ID: <1dafcdfb-9bf9-4e82-8768-1b1905fc204a@googlegroups.com> References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_3441_1350598450.1505389476567" X-Trace: blaine.gmane.org 1505389477 27098 195.159.176.226 (14 Sep 2017 11:44:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 14 Sep 2017 11:44:37 +0000 (UTC) To: pandoc-discuss Original-X-From: pandoc-discuss+bncBD7MBE7TSALRBJOX5HGQKGQEARH7P3I-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Sep 14 13:44:31 2017 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane.org Original-Received: from mail-io0-f183.google.com ([209.85.223.183]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dsSZK-0006s8-Li for gtp-pandoc-discuss@m.gmane.org; Thu, 14 Sep 2017 13:44:31 +0200 Original-Received: by mail-io0-f183.google.com with SMTP id n69sf2445486ioi.11 for ; Thu, 14 Sep 2017 04:44:38 -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=2/+qYrNhrlrjfmPDDpvAtaNEotxY4VPzJc8+fgUTE78=; b=kjMNb7+eQO36yI0idMgwbMu7tVinqif4j600A74T5AJTkYyJqDHAaO8qHZiO0NehQt aFWQcSiBGkG7RQ71aT+/NAWUQClsXRYnlkoZzRtHtnEdRwYdAl8n+gzOVxIFtFlGfVd7 rotijX2RHO2vZD0cPoV8dF1bFE7cOTfeFFtZ6ATbjQ5bMib/kiPZtHEdGg+TSU4WpF+a lKaQhFsDfm2n0IKhwSy0sP99E+56J5UbfT2edXp2AJxcq0I+eNp4Ed/lyLTi/vfFfine ZFUmqYTqYQmcST/cDcbMTDlfTiHwiWvqzmJlCt0GZM3tE9xG2fMRXZRq4g/OMqvHXGoc 287A== 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=2/+qYrNhrlrjfmPDDpvAtaNEotxY4VPzJc8+fgUTE78=; b=TMGPNhoTy2YY+naifDqPXBDMhLD4NMYlU7YDfs9Fbes6+2nymt90WJn2zSZQIIRgBV 8usgRcKZZ4kBQr0Up/l9Bi5TUyWDgDhrLqMuJyMAxjldigPrj73dQcLCh4OklWR2An6D jjDE1lWaLPZa5UdLtR2k71CyFyzvUZcxTu2UTL7U/T8wX5VaiOwbUV3D8ux8wIE/fHVs twTga+hpWXYI1VFv8V+HSs9nxrvqhogP9WXteWtTBerFxzsQSBOP3ClE4IstVgUoEgMD A3s+1RLwHy8vcjTexFEXVnwC5QiyiCDgcCrAMhrbn83mT6ekQ5uFv6RukuPlr/T2SdKW w+XA== 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=2/+qYrNhrlrjfmPDDpvAtaNEotxY4VPzJc8+fgUTE78=; b=gEyyX2zvuV2DrkGDpbwPycHWWvdcVHqPpDNt2l9TMQeRx1doipvteMuvcrwfiTh87q 1gJmfIhvIJboMapwvV4jLYncjZFFahz9muOmpMpkA8JRFWqyvYpVkzwCu0qEOehXer+v 5lE3ZghOJ6S5ohI/fuNoCrVJqapeZgHvYFPJ0PiKlsfPbqDQuLLdf7vzwEI9fFlpYkU+ gkqVRH3lAutym3n5QObxqOCeuKp/NhYe60MYXPbGyBsBG08X5SOyThrUf5Mr3ZL/Z9h9 hsHd8kZSm7Bt8CN/929Xg8myLCGV4AAAdStv46s8QO1sGsKRHZ1pfLTpKpYRMfGHraw3 Advg== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AHPjjUgh2vxbeBiJrdxhFG6VAiPfNjbO+S30M1r34id08iZqGvShP11s Lalypamqa8SGGg== X-Google-Smtp-Source: AOwi7QBLo2OiHOnv2kqkA+eIMqGxVsiqdNRu7Cq2GqUABde0zQDIkME7gqVMmTmq1tc977iuYqrsvw== X-Received: by 10.36.246.203 with SMTP id u194mr91640ith.2.1505389477944; Thu, 14 Sep 2017 04:44:37 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 10.107.180.22 with SMTP id d22ls2736851iof.48.gmail; Thu, 14 Sep 2017 04:44:37 -0700 (PDT) X-Received: by 10.36.33.4 with SMTP id e4mr87623ita.11.1505389477166; Thu, 14 Sep 2017 04:44:37 -0700 (PDT) In-Reply-To: X-Original-Sender: janhermes.JH-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.org gmane.text.pandoc:18173 Archived-At: ------=_Part_3441_1350598450.1505389476567 Content-Type: multipart/alternative; boundary="----=_Part_3442_1392143562.1505389476569" ------=_Part_3442_1392143562.1505389476569 Content-Type: text/plain; charset="UTF-8" Thank you very much for sharing! Unfortunately this produces an error "IndexError:list index out of range" in a recent pandoc version: 1.19.2.1 Traceback (most recent call last): File "filters/tabular.py", line 53, in pf.toJSONFilter(do_filter) File "/usr/local/lib/python2.7/dist-packages/pandocfilters.py", line 132, in toJSONFilter toJSONFilters([action]) File "/usr/local/lib/python2.7/dist-packages/pandocfilters.py", line 166, in toJSONFilters sys.stdout.write(applyJSONFilters(actions, source, format)) File "/usr/local/lib/python2.7/dist-packages/pandocfilters.py", line 197, in applyJSONFilters altered = walk(altered, action, format, meta) File "/usr/local/lib/python2.7/dist-packages/pandocfilters.py", line 124, in walk x[k] = walk(x[k], action, format, meta) File "/usr/local/lib/python2.7/dist-packages/pandocfilters.py", line 111, in walk item['c'] if 'c' in item else None, format, meta) File "filters/tabular.py", line 46, in do_filter tbl_headers(v[3]), File "filters/tabular.py", line 22, in tbl_headers result = s[0][0]['c'][:] IndexError: list index out of range pandoc: Error running filter filters/tabular.py Filter returned error status 1 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 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/1dafcdfb-9bf9-4e82-8768-1b1905fc204a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. ------=_Part_3442_1392143562.1505389476569 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thank you very much for sharing!

Unfortunately this= produces an error "IndexError:list index out of range" in a rece= nt pandoc version: 1.19.2.1

Traceback (most recent call last):
=C2=A0
File "filters= /tabular.py", l= ine 53, in <module>
=C2=A0 =C2=A0 pf
.toJSONFilter(do_filter)
=C2=A0
File "/usr/local/lib/python2.7/dist-packages/pandocfilters.py"= , line 132, in toJSONFilter
=C2=A0 =C2=A0 toJSONFilters
([action])
=C2=A0
File "/usr/local/lib/python2.7/dist-packages/pandocfilters.= py",<= /span> line 166, in toJSONFilters
=C2=A0 =C2=A0 sys
.stdout.write(applyJSONFilters(actions, source= , format))
=C2=A0
File
"/usr/local/lib/python2.7/dis= t-packages/pandocfilters.py", line 197, in applyJSONFilters
= =C2=A0 =C2=A0 altered
=3D walk= (altered, action, format, meta)
=C2=A0
File "/usr/local/lib/python2.7/dist-packages/pandocfilters.py", line 124, in walk
=C2=A0 =C2=A0 x
[k] =3D walk<= span style=3D"color: #660;" class=3D"styled-by-prettify">(x[k], action, format,<= /span> meta)
=C2=A0
File "/usr/local/lib/python2.7/dist-p= ackages/pandocfilters.py", line 111= , <= span style=3D"color: #008;" class=3D"styled-by-prettify">in
walk
=C2=A0 =C2=A0 ite= m
[<= span style=3D"color: #080;" class=3D"styled-by-prettify">'c'
= ] if 'c' in item else <= /span>None= , format, meta)
=C2=A0
File "filters/tabular.py", line 46,= in= do_filter
=C2= =A0 =C2=A0 tbl_headers
(v[3]),
=C2=A0
File "filters/tabular.py", line 22, in tbl_headers
=C2=A0 =C2=A0 result
=3D s[0][0]['c'][:]
IndexError: list index out of range
pandoc
: Error running filter filters/tabular.py
Filter re= turned error status 1




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 witho= ut needing, so I took advantage of the filtering mechanism and I did a filt= er 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 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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/= msgid/pandoc-discuss/1dafcdfb-9bf9-4e82-8768-1b1905fc204a%40googlegroups.co= m.
For more options, visit http= s://groups.google.com/d/optout.
------=_Part_3442_1392143562.1505389476569-- ------=_Part_3441_1350598450.1505389476567--