首先,在尝试编译以下 MWE 之前,请确保您已经安装了 Kanji Stroke Order 字体。该字体可以下载此处(点击)。
我想创建一个关于我学习日语的笔记。在环境中,enumerate
我将制作一个日语和英语句子列表。中文字符将被渲染两次,即第一次在日语句子中,第二次在表格中。我的代码的期望输出如下。
最小工作示例
\documentclass[dvipsnames]{article}
\usepackage[a5paper,hmargin=1cm,vmargin=15mm]{geometry}
\usepackage{xeCJK}
\setmainfont{Cambria}
\setCJKmainfont{ipaexm.ttf} % For furigana and other Japanese characters
\newCJKfontfamily\strokefont{KanjiStrokeOrders_v3.001.ttf} % For stroke order
\usepackage{ruby}
\usepackage[many]{tcolorbox}
\def\GlobalSettings{%
\renewcommand\rubysep{0pt}%
\renewcommand\rubysize{0.4}%
\let\oldruby\ruby%
\renewcommand\ruby[2]{\oldruby{##1}{\textcolor{Red}{##2}}}%
}
\AtBeginDocument{\GlobalSettings}
\def\LocalSettings{%
\renewcommand\rubysep{1ex}%
\renewcommand\rubysize{.3}%
\renewcommand\ruby[2]{\oldruby{\fontsize{65}{0}\selectfont\strokefont##1}{\fontsize{15}{0}\selectfont\textcolor{Red}{##2}}}%
}
\def\FlashCard[#1]#2{\begin{tcolorbox}\LocalSettings{\fontsize{15}{0}\selectfont#1\par}\vspace{15pt}\textcolor{Cyan}{\bfseries#2}\end{tcolorbox}}
\newcommand\DeclareWord[4][]{%
\expandafter\newcommand\csname #2#1\endcsname{#3}%
\expandafter\gdef\csname #2#1FC\endcsname{\FlashCard[#3]{#4}}%
}
\newenvironment{Table}
{\begin{tcbraster}[%
raster height=\textwidth,
raster width=\linewidth,
raster columns=2,
raster rows=3,
size=fbox,
sharp corners,
halign=flush center,
valign=center,
boxrule=2pt, % line width
raster column skip=-2pt, % negative line width
raster row skip=-2pt, % negative line width
colframe=Red,
colback=White,
]}
{\end{tcbraster}}
\begin{document}
\begin{enumerate}
\item \DeclareWord{kare}{\ruby{彼}{かれ}}{he}%
\DeclareWord{samui}{\ruby{寒}{さむ}い}{cold}%
\kare は\samui です。\\
\textcolor{red}{He is cold.}
\Table
\kareFC
\samuiFC
\endTable
\item \DeclareWord{jikan}{\ruby{時}{じ}\ruby{間}{かん}}{time}%
\DeclareWord{kichou}{\ruby{貴}{き}\ruby{重}{ちょう}}{precious}%
\DeclareWord{kenmei}{\ruby{賢}{けん}\ruby{明}{めい}}{wise}%
\DeclareWord{tsukau}{\ruby{使}{つか}う}{to use (N1)}%
\jikan は\kichou なので、\kenmei にそれを\ruby{使}{つか}います。\\
\textcolor{red}{As time is precious, use it wisely.}
\Table
\jikanFC
\kichouFC
\kenmeiFC
\tsukauFC
\endTable
\end{enumerate}
\end{document}
问题
为了使输入文件尽可能简单,我想我不需要写
..............
\Table
\kareFC
\samuiFC
\endTable
..............
\Table
\jikanFC
\kichouFC
\kenmeiFC
\tsukauFC
\endTable
..............
我的意思是应该自动创建表。如何做到这一点?
答案1
我无法使字体正常工作,但我有一种可能有效的方法:
对于每个定义的单词,都会定义一个附加的编号命令就像对“数组”所做的那样执行时,会调用相关的闪存卡命令。一旦定义了所有所需的单词,就会调用一个命令来建立环境并循环遍历已定义的命令,调用每个闪存卡。最后,计数器被重置,为下一组单词准备“数组”。此基础结构由以下处理(\begin{figure}[h]
用于代替\Table
以缓解字体问题):
\usepackage{etoolbox}
% Array for words
\makeatletter
\newcounter{jwordcount}%
\newcommand\setjword[2]{\csdef{jword#1}{#2}}%
\newcommand\addjword[1]{\stepcounter{jwordcount}\setjword{\thejwordcount}{#1}}%
\newcommand\getjword[1]{\csuse{jword#1}}%
%%% Basic Loop
%Taken from the aloop pof David Salomon's The Advanced TeXbook pg 191
%Use:
%\newcount\temp
%\loop\temp=1 step 1 until 10 do {something} \endloop\temp
\def\loop#1=#2 {%
\long\def\next step ##1 until ##2 do ##3 \endloop#1{%
##3%
\advance#1 by ##1
\ifnum#1>##2\relax\else\next step ##1 until ##2 do ##3 \endloop#1 \fi%
}%end of \next
#1=#2 \next}%end of \loop
%Return the table containing the current words, reset the counter
\newcommand\currentwordtable{%
\begin{figure}[h]%Replace with \Table
\newcount\temp\loop\temp=1 step 1 until {\thejwordcount} do {\expandafter\getjword{\@arabic\temp}\ifnum\temp<\thejwordcount\else\fi} \endloop\temp%
\setcounter{jwordcount}{0}%reset for the next group of words
\end{figure}}%replace with \endTable
\makeatother
除了改变上述环境之外,它还可以通过插入命令来纳入到您的工作流程中\addjword
,\DeclareWord
具体来说:
\newcommand\DeclareWord[4][]{%
\expandafter\newcommand\csname #2#1\endcsname{#3}%
\expandafter\gdef\csname #2#1FC\endcsname{\FlashCard[#3]{#4}}%
\expandafter\addjword{\csname #2#1FC\endcsname}%
}
最后,要使用它,您需要用 替换您的\Table ... \endTable
块\currentwordtable{}
。
编辑:这对我来说都是希腊语
\ruby
以下是替换希腊字母并省略调用的结果:
\documentclass[dvipsnames]{article}
\usepackage[a5paper,hmargin=1cm,vmargin=15mm]{geometry}
\usepackage{xeCJK}
\setmainfont{Cambria}
\setCJKmainfont{ipaexm.ttf} % For furigana and other Japanese characters
\newCJKfontfamily\strokefont{KanjiStrokeOrders_v3.001.ttf} % For stroke order
\usepackage{ruby}
\usepackage[many]{tcolorbox}
\def\GlobalSettings{%
\renewcommand\rubysep{0pt}%
\renewcommand\rubysize{0.4}%
\let\oldruby\ruby%
\renewcommand\ruby[2]{\oldruby{##1}{\textcolor{Red}{##2}}}%
}
\AtBeginDocument{\GlobalSettings}
\def\LocalSettings{%
\renewcommand\rubysep{1ex}%
\renewcommand\rubysize{.3}%
\renewcommand\ruby[2]{\oldruby{\fontsize{65}{0}\selectfont\strokefont##1}{\fontsize{15}{0}\selectfont\textcolor{Red}{##2}}}%
}
\def\FlashCard[#1]#2{\begin{tcolorbox}\LocalSettings{\fontsize{15}{0}\selectfont#1\par}\vspace{15pt}\textcolor{Cyan}{\bfseries#2}\end{tcolorbox}}
\newcommand\DeclareWord[4][]{%
\expandafter\newcommand\csname #2#1\endcsname{#3}%
\expandafter\gdef\csname #2#1FC\endcsname{\FlashCard[#3]{#4}}%
\expandafter\addjword{\csname #2#1FC\endcsname}%
}
\newenvironment{Table}
{\begin{tcbraster}[%
raster height=\textwidth,
raster width=\linewidth,
raster columns=2,
raster rows=3,
size=fbox,
sharp corners,
halign=flush center,
valign=center,
boxrule=2pt, % line width
raster column skip=-2pt, % negative line width
raster row skip=-2pt, % negative line width
colframe=Red,
colback=White,
]}
{\end{tcbraster}}
\usepackage{etoolbox}
% Array for words
\makeatletter
\newcounter{jwordcount}%
\newcommand\setjword[2]{\csdef{jword#1}{#2}}%
\newcommand\addjword[1]{\stepcounter{jwordcount}\setjword{\thejwordcount}{#1}}%
\newcommand\getjword[1]{\csuse{jword#1}}%
%%% Basic Loop
%Taken from the aloop pof David Salomon's The Advanced TeXbook pg 191
%Use:
%\newcount\temp
%\loop\temp=1 step 1 until 10 do {something} \endloop\temp
\def\loop#1=#2 {%
\long\def\next step ##1 until ##2 do ##3 \endloop#1{%
##3%
\advance#1 by ##1
\ifnum#1>##2\relax\else\next step ##1 until ##2 do ##3 \endloop#1 \fi%
}%end of \next
#1=#2 \next}%end of \loop
%Return the table containing the current words, reset the counter
\newcommand\currentwordtable{%
\Table
\newcount\temp\loop\temp=1 step 1 until {\thejwordcount} do {\expandafter\getjword{\@arabic\temp}\ifnum\temp<\thejwordcount\else\fi} \endloop\temp%
\setcounter{jwordcount}{0}%reset for the next group of words
\endTable}
\makeatother
\begin{document}
\begin{enumerate}
\item \DeclareWord{kare}{$\alpha$}{he}%
\DeclareWord{samui}{$\beta$}{cold}%
\kare $\alpha$\samui $\beta$\\
\textcolor{red}{He is cold.}
\currentwordtable
% \Table
% \kareFC
% \samuiFC
% \endTable
\item \DeclareWord{jikan}{$\gamma$}{time}%
\DeclareWord{kichou}{$\delta$}{precious}%
\DeclareWord{kenmei}{$\epsilon$}{wise}%
\DeclareWord{tsukau}{$\zeta$}{to use (N1)}%
\jikan $gamma$\kichou $\delta$ \kenmei $\epsilon$ $\zeta$\\
\textcolor{red}{As time is precious, use it wisely.}
\currentwordtable
% \Table
% \jikanFC
% \kichouFC
% \kenmeiFC
% \tsukauFC
% \endTable
\end{enumerate}
\end{document}
产量: