
答案1
以下解決方案建立一個名為\bp
-- 縮寫為“的巨集”乙奧托姆對齊plus 符號”,我想——這又是基於包\genfrac
的宏amsmath
。
\documentclass{article} % or some other suitable document class
\usepackage{amsmath} % for '\genfrac' macro
\newcommand{\temp}[1]{\genfrac{}{}{0pt}{}{}{#1}}
\newcommand\bp{\mathbin{\temp{+}}} % or: \newcommand\bp{\temp{+}}
\begin{document}
\[
\frac{426}{359} = 1+\frac15\bp\frac12\bp\frac11\bp\frac13\bp\frac11\bp\frac14 \,,
\]
\end{document}
答案2
您可以使用更簡單的使用者層級語法來完成此操作。
該命令\contfrac
有
- 用於列印值的可選參數,後跟=;
- 整數部分的強制參數;若為空則不列印任何內容;
- 連分數中整數序列的強制參數;
- 用於列印 = 前面的值的可選參數。
當然,必須在前導可選參數和尾隨可選參數之間進行選擇。
當然,這僅用於顯示器。
\documentclass{article}
\usepackage{amsmath,xparse}
\NewDocumentCommand{\contfrac}{ommo}{%
\sbox0{$\dfrac{1}{1}$}%
\raisebox{-\dimexpr\dp0}{%
\raisebox{\dimexpr\dp0}{%
$\displaystyle\IfValueT{#1}{#1=}\NotBlankT{#2}{#2+{}}$%
}%
\makecontfrac{#3}%
\IfValueT{#4}{%
\raisebox{\dimexpr\dp0}{$\displaystyle{}=#4$}%
}%
}%
}
\ExplSyntaxOn
\NewExpandableDocumentCommand{\NotBlankT}{mm}
{
\tl_if_blank:nF { #1 } { #2 }
}
\NewDocumentCommand{\makecontfrac}{m}
{
\seq_set_from_clist:Nn \l_tmpa_seq { #1 }
\seq_set_map:NNn \l_tmpb_seq \l_tmpa_seq { \__coeus_rfrac:n { ##1 } }
$\displaystyle\seq_use:Nn \l_tmpb_seq { + }$
}
\cs_new_protected:Nn \__coeus_rfrac:n
{
\raisebox{\depth}{$\dfrac{1}{#1}$}
}
\ExplSyntaxOff
\begin{document}
\begin{gather}
\contfrac{}{5,2,1,3,1,4}
\\[2ex]
\contfrac{1}{5,2,1,3,1,4}
\\[2ex]
\contfrac[\frac{426}{359}]{1}{5,2,1,3,1,4}
\\[2ex]
\contfrac{1}{5,2,1,3,1,4}[\frac{426}{359}]
\end{gather}
\end{document}
這個想法是列印結果和由標準分數的深度引起的整數部分;那麼所有分數都會升高相同的量,因此 + 符號會以其常規高度排版。
最後我們降低了整個東西以掩蓋我們的蹤跡。