4

I want to have a newenvironment body as an inline input argument for pgfplotstable. Is it possible to do this without using braces in the body itself?

\documentclass{article}
\usepackage{pgfplotstable}

\newenvironment{customtabular}
{
\pgfplotstabletypeset[
    col sep=tab,
    row sep=\\,
    string type,
    ]
}
{}

\begin{document}

\begin{customtabular}
{foo    bar\\} %tab here
\end{customtabular}

\end{document}
3
  • The environ package should be able to do this.
    – JPi
    Commented Aug 9, 2014 at 13:43
  • Care to give a working example? I get the error Package pgfplots Warning: You requested to open table 'foo bar\\', but there is also a 'foo bar\\.tex'. Adding format=inline "works", but the table will not show up.
    – cmz
    Commented Aug 9, 2014 at 20:08
  • I have (as usual) trouble with TeX expansions. But this might help. tex.stackexchange.com/questions/14390/…
    – JPi
    Commented Aug 10, 2014 at 11:55

1 Answer 1

2

This is a simple example

\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\makeatletter

\def\pgfplotstabletypeset@env{%
    \pgfutil@ifnextchar[{%  
        \pgfplotstabletypeset@opt@env
    }{%
        \pgfplotstabletypeset@opt@env[]%
    }%
}
\long\def\pgfplotstabletypeset@opt@env[#1]{%
    \begingroup
    \ifpgfplots@table@options@areset
    \else
        \pgfplotstableset{#1}%
    \fi
    \pgfplotstablecollectoneargwithpreparecatcodes{%
        \pgfplotstabletypeset@opt@collectarg@env[#1]%
    }%
}
\long\def\pgfplotstabletypeset@opt@collectarg@env[#1]#2\end{%
    \pgfplotstable@isloadedtable{#2}%
        {\pgfplotstabletypeset@opt@[#1]{#2}}%
        {\pgfplotstabletypesetfile@opt@[#1]{#2}}%
    \end
}

\begin{pgfplotstabletypeset@env}[col sep=space,row sep=\\,string type]
    Lorem ipsum dolor sit amet, \\
    consectetur adipiscing elit. Sed augue \\
    sem, sollicitudin quis mauris sed, \\
    mattis aliquet diam. Aenean ultricies \\
    orci a ipsum imperdiet condimentum. \\
    Vivamus hendrerit consequat maximus. Ut \\
    auctor dignissim felis in faucibus. \\
    Proin quis vulputate arcu. Praesent \\
    iaculis consequat eros rutrum gravida. \\
    Duis nec volutpat enim, at \\
    fermentum quam. Pellentesque laoreet enim \\
    et neque fermentum luctus. end\\
\end{pgfplotstabletypeset@env}

\end{document}

Explanation

In pgfplotstable.code.tex line 1310-1331:

\def\pgfplotstabletypeset{%
  \pgfutil@ifnextchar[{%  
      \pgfplotstabletypeset@opt
  }{%
      \pgfplotstabletypeset@opt[]%
  }%
}
\long\def\pgfplotstabletypeset@opt[#1]{%
  \begingroup
  \ifpgfplots@table@options@areset
  \else
      \pgfplotstableset{#1}%
  \fi
  \pgfplotstablecollectoneargwithpreparecatcodes{%
      \pgfplotstabletypeset@opt@collectarg[#1]%
  }%
}
\long\def\pgfplotstabletypeset@opt@collectarg[#1]#2{%
  \pgfplotstable@isloadedtable{#2}%
      {\pgfplotstabletypeset@opt@[#1]{#2}}%
      {\pgfplotstabletypesetfile@opt@[#1]{#2}}%
}

This shows that braces in {table & contents \\} are mandatory because it becomes the second parameter of \pgfplotstabletypeset@opt@collectarg. But we can change the argument pattern --- by [#1]#2\end we mean that the second parameter is from ] to \end. Notice that right after the \end there should be {pgfplotstabletypeset@env}. After typesetting the table, we put back another \end so LaTeX can end the environment pgfplotstabletypeset@env.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .