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.

The arraypackage redefines array in various ways. I was woundering if anyone had made a package containing a localized (prefixed) version of the kernel array?

I have a document were we have a simple construction that make use of array some of the configurations we use does not work as soon as one load the array package (which can be nice for other things), so I wanted to create a copy prefix with say \my@ such that I could use both. So far unsuccessfull.

Basically the only problem is the restrictions that array puts on the format parser, so I would also be enough to locally restore the format parser.

Any ideas?

as for an MWE:

\documentclass{article}
%\usepackage{array}
\def\test{cc}
\begin{document} 
\[
  \begin{array}{\test}
    a & b \\ c & d
  \end{array}
\]
\end{document}

without the array package the code compiles just fine

EDIT:

Some more back ground. In a book we have a lot of linear equations and such that traditionally in this field is typeset via array in order to line up variables etc. We call this a system. Now instead of having to remember all those differnt array preambles we are creating a new environment what can be controlled via a key-val interface. This way we can for example make sure that all systems have a different \arraycolsep than the rest of the document. We can scale a system etc.

Usually all columns have the same alignment (r), but for some systems it is preferable to be able to specify a specific format, or even just specify the number of columns and then the format of just the last column.

As already mentioned, this is easy with the kernel array, but does not work because of the restrictions when the array package is loaded.

For the systems we (currently) do not need any of the extra array features.

Hope this clearify things a bit

share|improve this question
add comment

4 Answers

up vote 7 down vote accepted

You could keep the array package definition but just pre-expand the preamble

\documentclass{article}
\usepackage{array}


\makeatletter

\let\savearray\@@array
\def\@@array[#1]#2{%
\protected@edef\temp{\noexpand\savearray[#1]{#2}}\temp}
\makeatother

\def\test{cc}

\begin{document} 
\[
  \begin{array}{\test}
    a & b \\ c & d
  \end{array}
\]
\end{document}

This redefinition doesn't stop the usual array package features so long as any commands placed in >{...} are latex-robust so don't fail in the protected edef.

share|improve this answer
    
Nice, that seem to do the trick in small scale. –  daleif Jun 29 '12 at 14:07
    
I will use yours thanks –  daleif Jun 29 '12 at 14:15
add comment

Use at your own risk

\documentclass{article}
\usepackage{array}

\makeatletter
\let\array@@array\array
\def\after@array#1#2{\array@@array[#2]{#1}}
\renewcommand{\array}[2][c]{\expandafter\after@array\expandafter{#2}{#1}}
\makeatother

\def\test{cc}
\begin{document}
\[
  \begin{array}{\test}
    a & b \\ c & d
  \end{array}
\]
\end{document}
share|improve this answer
    
that almost works, but the parser still complains if one use *{3}{\test}, would it be enough to restore the argument parser to the original version? –  daleif Jun 29 '12 at 13:40
    
@daleif I'd say no, if you want to use the extended syntax provided by array. I can understand the need to have a one-level expansion; giving an option such as format=*{3}{\test} is quite mysterious. Would you like to improve your question adding some details? –  egreg Jun 29 '12 at 13:44
    
One would never give format=*{3}[\test}, at least that is not what is indented, but the overall alignment of the matrix is stored in a macro, so at some point *{NUM}{\macro} will be used. –  daleif Jun 29 '12 at 14:05
    
@daleif Expand \macro yourself before passing it to array. Or use David's strategy, which is riskier if you don't have full control on what is passed. –  egreg Jun 29 '12 at 14:08
    
Davids solution seem to work as indented –  daleif Jun 29 '12 at 14:14
add comment

why can't you use this definition? Maybe I didn't understand your problem ...

\documentclass{article}
\usepackage{array}
\newcolumntype{C}{cc}
\begin{document} 
\[
  \begin{array}{C}
    a & b \\ c & d
  \end{array}
\]
\end{document}
share|improve this answer
    
because the entire format for the array is build via key-val options, most times it is just *{NUM c} but it may also be supplied as format=rrllccrllrc or other options –  daleif Jun 29 '12 at 13:08
add comment

I have localised array package in xepersian. Some pieces of code with explanation:

\def\@testpach{\@chclass
 \ifnum \@lastchclass=6 \@ne \@chnum \@ne \else
  \ifnum \@lastchclass=7 5 \else
   \ifnum \@lastchclass=8 \tw@ \else
    \ifnum \@lastchclass=9 \thr@@
   \else \z@
   \ifnum \@lastchclass = 10 \else
   \edef\@nextchar{\expandafter\string\@nextchar}%
   \@chnum
   \if \@nextchar c\z@ \else
   \if \@nextchar و\z@ \else
    \if \@nextchar \if@RTLtab r\else l\fi\@ne \else
    \if \@nextchar \if@RTLtab ر\else چ\fi\@ne \else
     \if \@nextchar \if@RTLtab l\else r\fi\tw@ \else
     \if \@nextchar \if@RTLtab چ\else ر\fi\tw@ \else
   \z@ \@chclass
   \if\@nextchar |\@ne \else
    \if \@nextchar !6 \else
     \if \@nextchar @7 \else
      \if \@nextchar <8 \else
       \if \@nextchar >9 \else
  10
  \@chnum
  \if \@nextchar m\thr@@\else
  \if \@nextchar م\thr@@\else
   \if \@nextchar p4 \else
  \if \@nextchar پ4 \else
    \if \@nextchar b5 \else
    \if \@nextchar ز5 \else
   \z@ \@chclass \z@ \@preamerr \z@ \fi \fi \fi \fi \fi \fi \fi
   \fi \fi  \fi  \fi  \fi  \fi  \fi \fi \fi \fi \fi \fi \fi \fi \fi}%

This code comes from file misc-localise-xepersian.def. It localises position arguments. Persian و‍ for c, ر‍ for r, چ for l, م for m, پ for p, ز for b.

\eqenvironment{آرایه}{array}

This is from file environments-ltx.def. It makes Persian environment آرایه equivalent to array environment.

\eqenvironment{جدول}{tabular}

Similar to above. It makes Persian environment جدول equivalent to tabular environment.

share|improve this answer
    
Nice, but I think I have misused the localize part. I meant it as a prefix of all of the macros used, in the same manner as many of the internal memoir macros are prefixed \m@m –  daleif Jun 29 '12 at 13:20
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.