透過 datatool 處理時如何將 CSV 中的特殊字元對應到其他內容

透過 datatool 處理時如何將 CSV 中的特殊字元對應到其他內容

datatool 使用者指南提到在載入資料庫時,某些特殊字元會自動對應到排版等效字符生的模式(通過\DTLloadrawdb)。如果您想更改映射,請使用(例如)

\DTLrawmap{£}{\pounds}

然而,我該如何映射積極的%諸如, $, &, , ...之類的字符_會變成其他東西嗎?以下最小範例無法對應%到除\%(出於明顯原因;%是活躍註解字元)之外的其他內容:

\documentclass{article}

\usepackage{filecontents,datatool}
\begin{filecontents*}{scores.csv}
Name, Score
Alpha, 80.2%
Beta, 91.3%
Average, 85.75%
\end{filecontents*}

\begin{document}

\DTLrawmap{%}{\$}% <--- this fails...
\DTLloadrawdb{scores}{scores.csv}
\DTLdisplaydb{scores}

\end{document}

答案1

使用逃脫了<string>部分中的角色版本\DTLrawmap{<string>}{<replacement>}。例如,

\DTLrawmap{\%}{\$}

%在來源 CSV 中替換為\$

在此輸入影像描述

\documentclass{article}

\usepackage{filecontents,datatool}
\begin{filecontents*}{scores.csv}
Name, Score
Alpha, 80.2%
Beta, 91.3%
Average, 85.75%
\end{filecontents*}

\begin{document}

\DTLloadrawdb{scoresA}{scores.csv}
\DTLdisplaydb{scoresA}

\DTLrawmap{\%}{\$}% Map % to \$
\DTLloadrawdb{scoresB}{scores.csv}
\DTLdisplaydb{scoresB}

\end{document}

來自datatool 使用者指南:

當然,必須設定映射事先的載入數據\DTLloadrawdb

相關內容