在內聯數學模式中使用 \input{} - 額外的 `}`

在內聯數學模式中使用 \input{} - 額外的 `}`

我產生某些值並example.tex在 python 中將它們列印在單一 .tex-files () 中,主要以表格環境的形式\SI{<value>}{\percent}或單行形式列印& \SI{<value>}{\percent} & \SI{<value>}{\percent} & \SI{<value>}{\percent}

但是,我可以輕鬆地\input{example.tex}將該值包含在普通文字aligntabular環境中,而不會出現任何問題。但是,當在表格標題的數學模式($$\[\]、 )中使用它時,日誌檔案會在輸入位置\ensuremath產生「...額外」。}

Pdlatex 編譯並顯示值,因為警告是一個錯誤,我想問:

1) Is the use of `\input{}` for this purpose generally recommended?
2) How to get rid of the error/what did I do wrong?

在 MWE 下面,test_size.tex純粹由\SI{30}{\percent}.

\documentclass{article}

\usepackage{siunitx}
\usepackage{amsmath}


\begin{document}
    Normal inline mode works: \input{./values/test_size.tex}\\[1ex]
    Normal math inline mode works: $\input{./values/test_size.tex}$
    \begin{table}
        \caption{Math inline caption doesnt work: $\input{./values/test_size.tex}$}
    \end{table}
    \begin{align}
        \textrm{align enviroment works: } \input{./values/test_size.tex}
    \end{align}
\end{document}

編輯:也會有幫助的。抱歉重複發文。

答案1

\input是瀕危物種,需要保護,要利用\protect\input

不過,為什麼要先包含這樣的數據呢?

相關內容