Windows10 で W32TeX の pLaTeX を使っています。
% pLaTeX
\documentclass[dvipdfmx]{jsarticle}
\newcommand{\hoge}[3]{#1}%
\newcommand{\fuga}[2]{#1}%
\pagestyle{empty}
\begin{document}
\begin{tabular}{ccc}%% OK
\hoge{9}{8}{7}\\
\fuga{5}{6}&\\
\end{tabular}
\end{document}
上記の例だと上手くいくのですが、tabular環境をコマンドにして以下のようにしました。
% pLaTeX
\documentclass[dvipdfmx]{jsarticle}
\newcommand{\hoge}[3]{#1}%
\newcommand{\fuga}[2]{#1}%
\newcommand{\hogefuga}{%
\begin{tabular}{ccc}
\hoge{##1}{##2}{##3}\\
\fuga{##1}{##2}&\\
\end{tabular}}
\pagestyle{empty}
\begin{document}
\hoge{3}{4}{5}
\fuga{8}{9}
\hogefuga%% NG
\end{document}
ところが、これは上手く行きません。
以下のようなエラーを吐きます。
This is e-pTeX, Version 3.141592653-p3.9.0-210218-2.6 (utf8.sjis) (TeX Live 2021/W32TeX) (preloaded format=platex)
restricted \write18 enabled.
entering extended mode
(./ng.tex
pLaTeX2e <2020-10-01>+2 (based on LaTeX2e <2020-10-01> patch level 4)
L3 programming layer <2021-02-18>
Babel <3.55> and hyphenation patterns for 83 language(s) loaded.
(c:/usr/local/share/texmf-dist/tex/platex/jsclasses/jsarticle.cls(guessed encoding: UTF-8 = utf8)
Document Class: jsarticle 2020/10/09 jsclasses (okumura, texjporg)
(c:/usr/local/share/texmf-dist/tex/platex/jsclasses/jslogo.sty))
(c:/usr/local/share/texmf-dist/tex/latex/l3backend/l3backend-dvipdfmx.def
(|extractbb --version))
No file ng.aux.
! Misplaced alignment tab character &.
\hoge #1#2#3->#1&
#2
l.17 \hoge{3}{4}{5}
苦し紛れに次のようにしてみました。
% pLaTeX
\documentclass[dvipdfmx]{jsarticle}
%\newcommand{\hoge}[3]{#1}%
\newcommand{\hoge}[3]{#1\\}%
%\newcommand{\fuga}[2]{#1}%
\newcommand{\fuga}[2]{#1\}%
\newcommand{\hogefuga}{%
\begin{tabular}{ccc}
\hoge{##1}{##2}{##3}\\
\fuga{##1}{##2}&\\
\end{tabular}}
\pagestyle{empty}
\begin{document}
\hoge{3}{4}{5}
\fuga{8}{9}
\hogefuga%% NG
\end{document}
しかし、別なエラーを吐いてしまいました
This is e-pTeX, Version 3.141592653-p3.9.0-210218-2.6 (utf8.sjis) (TeX Live 2021/W32TeX) (preloaded format=platex)
restricted \write18 enabled.
entering extended mode
(./ng2.tex
pLaTeX2e <2020-10-01>+2 (based on LaTeX2e <2020-10-01> patch level 4)
L3 programming layer <2021-02-18>
Babel <3.55> and hyphenation patterns for 83 language(s) loaded.
(c:/usr/local/share/texmf-dist/tex/platex/jsclasses/jsarticle.cls(guessed encoding: UTF-8 = utf8)
Document Class: jsarticle 2020/10/09 jsclasses (okumura, texjporg)
(c:/usr/local/share/texmf-dist/tex/platex/jsclasses/jslogo.sty))
(c:/usr/local/share/texmf-dist/tex/latex/l3backend/l3backend-dvipdfmx.def
(|extractbb --version))
No file ng2.aux.
! You can't use `macro parameter character #' in restricted horizontal mode.
<recently read> ##
l.22 \hogefuga
%% NG
根本的に何か間違っていると思うのですが、自分では解決できません。どなたかご教示願います。
えーっと、こういう単純なやつではダメなのでしょうか…?
\documentclass[dvipdfmx]{jsarticle}
%\newcommand{\hoge}[3]{#1}%
%\newcommand{\fuga}[2]{#1}%
%
%\newcommand{\hogefuga}{%
% \begin{tabular}{ccc}
% \hoge{##1}{##2}{##3}\\
% \fuga{##1}{##2}&\\
% \end{tabular}}
\newcommand{\hoge}[3]{\def\saveHoge{#1}}
\newcommand{\fuga}[2]{\def\saveFuga{#1}}
\newcommand{\hogefuga}{%
\begin{tabular}{ccc}
\saveHoge\\
\saveFuga&\\
\end{tabular}}
\pagestyle{empty}
\begin{document}
\hoge{3}{4}{5}
\fuga{8}{9}
\hogefuga
\end{document}