.png)
グリッド上に石を描画しようとしていますが、マクロ API にはそれを実行する 2 つの方法があります。X 座標と Y 座標を指定するか、座標の文字列を指定します。つまり、たとえば、およびab
になります。X = 1
Y = 2
続く@PhelypeOleinikによるこの回答、私は今これを試しています:
\documentclass{article}
\usepackage{xstring}
\newcommand\makeFromAlph[1]{
\number\numexpr`#1-`a\relax % I should probably lowercase `#1` first...
}
% I've also tried this version:
% \ExplSyntaxOn
% \NewExpandableDocumentCommand \makeFromAlph { m }
% { \int_eval:n { \int_from_alph:n {#1} - 1 } }
% \ExplSyntaxOff
\begin{document}
\StrRight{ab}{1} % This works
\makeFromAlph{\StrRight{ab}{1}} % But this doesn't
\end{document}
しかし、次のエラー メッセージが表示されます:
Improper alphabetic constant.
<to be read again>
理由を知っている人はいますか? 出力が\StrRight
1 文字と見なされるものを生成していない可能性がありますか? これを修正するにはどうすればよいですか?
答え1
これは拡張によって機能するため、数値が予想される場所であればどこでも使用できます。
ここでは 2 つのバージョンを示します。1 つは古典的な latex2e\@firstoftwo
とを使用したもので\expandafter
、もう 1 つはよりシンプルな L3 バージョンです。
\documentclass{article}
\makeatletter
\newcommand\foo[1]{%
The first number is \the\numexpr \expandafter`\@firstoftwo#1-96\relax,
The second number is \the\numexpr \expandafter`\@secondoftwo#1-96\relax.
}
\makeatother
\ExplSyntaxOn
\cs_generate_variant:Nn \int_from_alph:n {e}
\newcommand\foob[1]{
\int_from_alph:e{\use_i:nn#1}, ~\int_from_alph:e{\use_ii:nn#1}.
}
\ExplSyntaxOff
\begin{document}
\foo{ab}
\foob{ab}
\end{document}