XeTeXを使っていて,フォント設定を簡単にするために次のようなコマンドを作ろうと思いました(フォント名は仮です):
\def\setMainFont[#1,#2,#3,#4,#5,#6]{\setmainfont[ItalicFont=#1-#4.#2,BoldFont=#1-#5.#2,BoldItalicFont=#1-#6.#2]{#1-#3.#2}}
\def\setSansFont[#1,#2,#3,#4,#5,#6]{\setsansfont[ItalicFont=#1-#4.#2,BoldFont=#1-#5.#2,BoldItalicFont=#1-#6.#2]{#1-#3.#2}}
\def\setMonoFont[#1,#2,#3,#4,#5,#6]{\setmonofont[ItalicFont=#1-#4.#2,BoldFont=#1-#5.#2,BoldItalicFont=#1-#6.#2]{#1-#3.#2}}
\def\setCJKMainFont[#1,#2,#3,#4,#5,#6]{\setCJKmainfont[ItalicFont=#1-#4.#2,BoldFont=#1-#5.#2,BoldItalicFont=#1-#6.#2]{#1-#3.#2}}
\def\setCJKSansFont[#1,#2,#3,#4,#5,#6]{\setCJKsansfont[ItalicFont=#1-#4.#2,BoldFont=#1-#5.#2,BoldItalicFont=#1-#6.#2]{#1-#3.#2}}
\def\setCJKMonoFont[#1,#2,#3,#4,#5,#6]{\setCJKmonofont[ItalicFont=#1-#4.#2,BoldFont=#1-#5.#2,BoldItalicFont=#1-#6.#2]{#1-#3.#2}}
\setMainFont[NotoSerif,ttf,Regular,Italic,Bold,BoldItalic]
\setSansFont[OpenSans,ttf,Regular,Italic,Bold,BoldItalic]
\setMonoFont[SourceCodePro,ttf,Regular,Bold,Bold,Bold]
\setCJKMainFont[NotoSerifCKJjp,otf,Regular,Bold,Bold,Bold]
\setCJKSansFont[NotoSansCJKjp,otf,Regular,Bold,Bold,Bold]
\setCJKMonoFont[NotoSansMonoCJKjp,otf,Regular,Bold,Bold,Bold]
% こうなってほしい
% \setmainfont[ItalicFont=NotoSerif-Italic.ttf,BoldFont=NotoSerif-Bold.ttf,BoldItalicFont=NotoSerif-BoldItalic.ttf]{NotoSerif-Regular.ttf}
% \setsansfont[ItalicFont=OpenSans-Italic.ttf,BoldFont=OpenSans-Bold.ttf,BoldItalicFont=OpenSans-BoldItalic.ttf]{OpenSans-Regular.ttf}
% \setmonofont[ItalicFont=SourceCodePro-Bold.ttf,BoldFont=SourceCodePro-Bold.ttf,BoldItalicFont=SourceCodePro-Bold.ttf]{SourceCodePro-Regular.ttf}
% \setCJKmainfont[ItalicFont=NotoSerifCJKjp-Bold.otf,BoldFont=NotoSerifCJKjp-Bold.otf,BoldItalicFont=NotoSerifCJKjp-Bold.otf]{NotoSerifCJKjp-Regular.otf}
% \setCJKsansfont[ItalicFont=NotoSansCJKjp-Bold.otf,BoldFont=NotoSansCJKjp-Bold.otf,BoldItalicFont=NotoSansCJKjp-Bold.otf]{NotoSansCJKjp-Regular.otf}
% \setCJKmonofont[ItalicFont=NotoSansMonoCJKjp-Bold.otf,BoldFont=NotoSansMonoCJKjp-Bold.otf,BoldItalicFont=NotoSansMonoCJKjp-Bold.otf]{NotoSansMonoCJKjp-Regular.otf}
しかし,これをコンパイルしようとすると次のエラーが出ます:
$ cat sample.tex
\documentclass[xelatex,ja=standard,a4paper,jafont=hiragino-pron,no-math]{bxjsarticle}
\usepackage{zxjatype}
\def\setMainFont[#1,#2,#3,#4,#5,#6]{\setmainfont[ItalicFont=#1-#4.#2,BoldFont=#1-#5.#2,BoldItalicFont=#1-#6.#2]{#1-#3.#2}}
\def\setSansFont[#1,#2,#3,#4,#5,#6]{\setsansfont[ItalicFont=#1-#4.#2,BoldFont=#1-#5.#2,BoldItalicFont=#1-#6.#2]{#1-#3.#2}}
\def\setMonoFont[#1,#2,#3,#4,#5,#6]{\setmonofont[ItalicFont=#1-#4.#2,BoldFont=#1-#5.#2,BoldItalicFont=#1-#6.#2]{#1-#3.#2}}
\def\setCJKMainFont[#1,#2,#3,#4,#5,#6]{\setCJKmainfont[ItalicFont=#1-#4.#2,BoldFont=#1-#5.#2,BoldItalicFont=#1-#6.#2]{#1-#3.#2}}
\def\setCJKSansFont[#1,#2,#3,#4,#5,#6]{\setCJKsansfont[ItalicFont=#1-#4.#2,BoldFont=#1-#5.#2,BoldItalicFont=#1-#6.#2]{#1-#3.#2}}
\def\setCJKMonoFont[#1,#2,#3,#4,#5,#6]{\setCJKmonofont[ItalicFont=#1-#4.#2,BoldFont=#1-#5.#2,BoldItalicFont=#1-#6.#2]{#1-#3.#2}}
\setMainFont[NotoSerif,ttf,Regular,Italic,Bold,BoldItalic]
\setSansFont[OpenSans,ttf,Regular,Italic,Bold,BoldItalic]
\setMonoFont[SourceCodePro,ttf,Regular,Bold,Bold,Bold]
\setCJKMainFont[NotoSerifCKJjp,otf,Regular,Bold,Bold,Bold]
\setCJKSansFont[NotoSansCJKjp,otf,Regular,Bold,Bold,Bold]
\setCJKMonoFont[NotoSansMonoCJKjp,otf,Regular,Bold,Bold,Bold]
\begin{document}
Hoge.
\end{document}
$ xelatex -halt-on-error -interaction=nonstopmode -file-line-error sample.tex
This is XeTeX, Version 3.14159265-2.6-0.99998 (TeX Live 2017) (preloaded format=xelatex)
restricted \write18 enabled.
entering extended mode
(./sample.tex
LaTeX2e <2017-04-15>
Babel <3.18> and hyphenation patterns for 84 language(s) loaded.
(/usr/local/texlive/texmf-local/tex/latex/bxjscls/bxjsarticle.cls
Document Class: bxjsarticle 2018/02/04 v1.7c BXJS document classes
(/usr/local/texlive/2017/texmf-dist/tex/latex/tools/calc.sty)
(/usr/local/texlive/2017/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/texmf-local/tex/latex/bxjscls/bxjscompat.sty)
(/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(/usr/local/texlive/2017/texmf-dist/tex/latex/geometry/geometry.sty
(/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/ifvtex.sty)
(/usr/local/texlive/2017/texmf-dist/tex/generic/ifxetex/ifxetex.sty))
(/usr/local/texlive/texmf-local/tex/latex/bxjscls/bxjsja-standard.def
(/usr/local/texlive/texmf-local/tex/latex/bxjscls/bxjsja-minimal.def)
(/usr/local/texlive/2017/texmf-dist/tex/latex/zxjatype/zxjatype.sty
(/usr/local/texlive/2017/texmf-dist/tex/xelatex/xecjk/xeCJK.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/local/texlive/2017/texmf-dist/tex/latex/l3kernel/l3xdvipdfmx.def))
(/usr/local/texlive/2017/texmf-dist/tex/latex/l3packages/xtemplate/xtemplate.st
y) (/usr/local/texlive/2017/texmf-dist/tex/latex/l3packages/xparse/xparse.sty)
(/usr/local/texlive/2017/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty)
(/usr/local/texlive/2017/texmf-dist/tex/latex/fontspec/fontspec.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/fontenc.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/tuenc.def))
(/usr/local/texlive/2017/texmf-dist/tex/latex/fontspec/fontspec.cfg)))
(/usr/local/texlive/2017/texmf-dist/tex/xelatex/xecjk/xunicode-addon.sty
(/usr/local/texlive/2017/texmf-dist/tex/xelatex/xunicode/xunicode.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/tipa/t3enc.def)
(/usr/local/texlive/2017/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2017/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/local/texlive/2017/texmf-dist/tex/latex/graphics-def/xetex.def)))))
(/usr/local/texlive/2017/texmf-dist/tex/xelatex/xunicode/xunicode.sty
*** Reloading Xunicode for encoding 'TU' ***
) (/usr/local/texlive/2017/texmf-dist/tex/xelatex/xecjk/xunicode-extra.def)
(/usr/local/texlive/2017/texmf-dist/tex/xelatex/xecjk/xeCJK.cfg)))
(/usr/local/texlive/2017/texmf-dist/tex/latex/zxjafont/zxjafont.sty
zxjafont: scale=0.924715/feat={}/preset=hiragino-pron/
)))
*************************************************
* xeCJK warning: "CJKfamily-redef"
*
* Redefining CJKfamily `\CJKrmdefault' (HiraginoMinchoProNW3(0)).
*************************************************
kpathsea:make_tex: Invalid fontname `[NotoSerifCKJjp-Regular.otf]/OT', contains '['
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
./sample.tex:12: fontspec error: "font-not-found"
!
! The font "NotoSerifCKJjp-Regular" cannot be found.
!
! See the fontspec documentation for further information.
!
! For immediate help type H <return>.
!...............................................
l.12 ...NotoSerifCKJjp,otf,Regular,Bold,Bold,Bold]
No pages of output.
Transcript written on sample.log.
引数の展開がうまくいっていないようだと思い「\expandafter\setCJKmainfont」や「\edef\setCJKMainFont」としてみましたが,いずれも同じエラーになります.
どうすればこのようなエラーを回避できるのでしょうか?