Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Still struggling with the \expandafter and \noexpand tex macros.

I'm trying to put a table together using pgfplotstable.

In this case the code is something like

\documentclass{article}
\usepackage{pgfplotstable}

\def\outline{\noexpand\fbox{{##1}}}

\begin{document}
\pgfplotstableread[row sep=\\,col sep=&,header=false]{%
1 & 2 & 3 & 4\\%
5 & 6 & 7 & 8\\%
9 & 10 & 11 & 12\\%
}\mytable

\pgfplotstabletypeset[
debug,
column name={},
every row 2 column 1/.style={postproc cell content/.style={@cell content=\outline}}
]\mytable

\end{document}

and gives the error you can't use macro parameter character in horizontal restricted mode. I f I escape the ##1 it replaces cell contents with ##1.

What I'm trying to do is eventually have a line that says something like:

every row 2 column 1/.style=\outline and a macro along the lines of

\def\outline{%
\{postproc cell content.style=%
\{@cell content=\noexpand\fbox{##1}\}\}}

What am I doing wrong?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

You are on the wrong track: the problem is unrelated to expansion control.

The problem is that your invocation of \outline does not communicate the argument - and the definition of \outline has no argument defined, although it requires one.

Once you fix these two points, you can come back to escaping #1 by ##1.

This here appears to work as desired:

\documentclass{article}
\usepackage{pgfplotstable}

\def\outline#1{\fbox{{#1}}}

\begin{document}
\pgfplotstableread[row sep=\\,col sep=&,header=false]{%
1 & 2 & 3 & 4\\%
5 & 6 & 7 & 8\\%
9 & 10 & 11 & 12\\%
}\mytable

\pgfplotstabletypeset[
debug,
column name={},
every row 2 column 1/.style={postproc cell content/.style={@cell content=\outline{##1}}}
]\mytable

\end{document}

enter image description here

I changed the definition of \outline (\def requires you to list the expected arguments in the definition) and the invocation of \outline. Note that the latter really requires ##1 (because #1 is the argument to every row 2 column 1 in that context and you want the argument to postproc cell content).


EDIT:

concerning the second part of your question and your comment on this answer: yes, it might be possible to define a style by means of a macro which expands to key-value assignments. But it is clearly not a best-practice. In fact, if it works, it might be luck.

If you want to have some sort of style which says "outline this cell", then you might be better of with something of sorts

% preamble:
\pgfplotstableset{
   outline/.style={postproc cell content/.style={@cell content=\outline{##1}}}
}

%code:
\pgfplotstabletypeset[
debug,
column name={},
every row 2 column 1/.style={outline},
]\mytable
share|improve this answer
    
Thanks @ChristianFeuersanger. A follow on from the second half of my question: when I change that to \def\outline#1{@cell content=\fbox{{#1}}} and the pgfplotstabletypeset to every row 2 column 1/.style={postproc cell content/.style={\outline{##1}} I get an illegal parameter number in definition of outline error. Do you know why that is? I'm eventually trying to get everything from postproc cell content.. built into the \outline macro –  Tahnoon Pasha Oct 30 '12 at 9:29
    
Do you mean something along the lines of my edit? –  Christian Feuersänger Oct 30 '12 at 18:08
    
Thank you very much for your help @ChristianFeuersanger. That is exactly what I needed. I just had a d'oh! moment when I saw your post. I'd forgotten how elegant pgf and pgfplotstable are for this stuff. –  Tahnoon Pasha Oct 31 '12 at 1:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.