返されたコマンド値を別の関数に渡す

返されたコマンド値を別の関数に渡す

コマンドの値を別の関数に渡そうとしていますが、うまくいきません。たとえば、\DTLloaddb[noheader, keys={key,value}]{definitions}{\data.def}でアクセスするデータがあります\DTLfetch{definitions}{key}{MyFromDate}{value}

data.defここで、この値を(例: 1990-10-09)からに渡して、\printdate{}この日付を自分の言語の優先形式にフォーマットできるようにします。1990年10月9日

\DTLfetch{}に格納されている戻り値を簡単に渡すことができると思いましたが、\printdate{}成功しませんでした。\printdate{\DTLfetch{definitions}{key}{MyFromDate}{value}}次のようなエラーがスローされます。! Illegal parameter number in definition of \iso@date.ただし、呼び出し\DTLfetch{definitions}{key}{MyFromDate}のみでは、フォーマットされていない (生の) 日付値が問題なく出力されます。

残念ながら、関数の値を別の関数に渡すことに関するヘルプ リソースは見つかりませんでした。このトピックについて追加情報を提供してくださる方がいらっしゃれば幸いです。ありがとうございます!

答え1

使用するパッケージ/ドキュメントクラスとマクロの呼び出し方法を示す最小限の (非) 動作例がありません。

おそらく\DTLfetchデータツールパッケージ\printdateから来ており、同位体パッケージ。


一方、コマンド\DTLfetch自体は完全に拡張可能なコマンドではありません。つまり、そのコマンドが呼び出されるたびに、(一時的な) 割り当てなどが実行されます。

一方、\printdate引数には次のトークンのみが含まれることが期待されます。

  • どちらも完全に拡張可能であり、ある段階での拡張により、日付を形成する文字列に属するトークンのみが生成される。
  • または日付を形成する文字列に属します。

しかし、このコマンドは\DTLfetch値を印刷/返すだけでなく、その値をマクロに保存します\dtlcurrentvalue
\dtlcurrentvalueつまり、完全に拡張可能です。

したがって、 を呼び出した後すぐに、の引数内で\DTLfetchマクロを使用できます。\dtlcurrentvalue\printdate

先ほど述べたように、\DTLfetch返された値も出力します。

値を印刷したくない場合は、 コマンドを使用せ\DTLfetchずに、代わりに コマンドを使用します\DTLgetvalueforkey。このコマンドでは、別の引数内で、目的の戻り値に展開されるように (再) 定義されるマクロの名前を指定できます。

\documentclass[english]{article}
\usepackage{datatool}
\usepackage[num]{isodate}
\usepackage{filecontents}

\begin{filecontents*}{MyDataFile.def}
WhatsoeverKeyA,WhatsoeverValueA
WhatsoeverKeyB,WhatsoeverValueB
MyFromDate,1990-10-09
WhatsoeverKeyC,WhatsoeverValueC
\end{filecontents*}


\newcommand\data{MyDataFile}
\DTLloaddb[noheader, keys={key,value}]{definitions}{\data.def}

\begin{document}

This does both print the return-value and save the return-value to
\verb|\dtlcurrentvalue|:

\verb|\DTLfetch{definitions}{key}{MyFromDate}{value}|:
\DTLfetch{definitions}{key}{MyFromDate}{value}\\
\begingroup\footnotesize
\verb|% use the database "definitions".|\\
\verb|% use the column whose name is "value".|\\
\verb|% use the row which in the column "key" holds the item "MyFromData".|
\endgroup

\verb|\dtlcurrentvalue| yields: \dtlcurrentvalue

Now you can use \verb|\dtlcurrentvalue| within the argument of 
\verb|\printdate|.

\verb|\printdate{\dtlcurrentvalue}| yields: \printdate{\dtlcurrentvalue}

\hrulefill

This does just save the return-value to the macro \verb|\MyCommand|:


\verb|\DTLgetvalueforkey{\MyCommand}{value}{definitions}{key}{MyFromDate}|\\
\begingroup\footnotesize
\verb|% define the macro "\MyCommand".|\\
\verb|% use the database "definitions".|\\
\verb|% use the column whose name is "value".|\\
\verb|% use the row which in the column "key" holds the item "MyFromData".|
\endgroup

\DTLgetvalueforkey{\MyCommand}{value}{definitions}{key}{MyFromDate}        

\verb|\MyCommand| yields: \MyCommand

Now you can use \verb|\MyCommand| within the argument of
\verb|\printdate|.

\verb|\printdate{\MyCommand}| yields: \printdate{\MyCommand}

\end{document}

ここに画像の説明を入力してください


日付を次のようにフォーマットします:
<name of the month><non-break-space><day>,<space><year>

私はこれを簡単に実現する方法を見つけられませんでした同位体パッケージです。
したがって、同位体パッケージを使用するが、パッケージを使用する日付時刻2そしてdatetime2 計算これらは、データツールパッケージ、ニコラ・タルボット博士

これらのパッケージを使用すると、好みに応じて新しい日付スタイルを簡単に定義できます。

\documentclass[english]{article}
\usepackage{datatool, datetime2, datetime2-calc}
\usepackage{filecontents}

\DTMnewdatestyle{MyDatestyle}{% definitions
  % the \number does remove leading zeros from the "day"-element of the date.
  \renewcommand*{\DTMdisplaydate}[4]{\DTMmonthname{##2}~\number##3, ##1}%
  \renewcommand*{\DTMDisplaydate}{\DTMdisplaydate}%
}

\begin{filecontents*}{MyDataFile.def}
WhatsoeverKeyA,WhatsoeverValueA
WhatsoeverKeyB,WhatsoeverValueB
MyFromDate,1990-10-09
WhatsoeverKeyC,WhatsoeverValueC
\end{filecontents*}

\newcommand\data{MyDataFile}
\DTLloaddb[noheader, keys={key,value}]{definitions}{\data.def}

\begin{document}

A new date-style can be defined using \textbf{datetime2 and datetime2-calc}:
\begin{verbatim}
\DTMnewdatestyle{MyDatestyle}{% definitions
  % the \number does remove leading zeros from the "day"-element of the date.
  \renewcommand*{\DTMdisplaydate}[4]{\DTMmonthname{##2}~\number##3, ##1}%
  \renewcommand*{\DTMDisplaydate}{\DTMdisplaydate}%
}
\end{verbatim}

\hrulefill

This does both print the return-value and save the return-value to
\verb|\dtlcurrentvalue|:

\verb|\DTLfetch{definitions}{key}{MyFromDate}{value}|:
\DTLfetch{definitions}{key}{MyFromDate}{value}\\
\begingroup\footnotesize
\verb|% use the database "definitions".|\\
\verb|% use the column whose name is "value".|\\
\verb|% use the row which in the column "key" holds the item "MyFromData".|
\endgroup

\verb|\dtlcurrentvalue| yields: \dtlcurrentvalue

Now you can use \verb|\dtlcurrentvalue| within the argument of
\verb|\DTMdate| and \verb|\DTMDate|.
\begin{verbatim}
\begingroup
\DTMsetdatestyle{MyDatestyle}
\DTMdate{\dtlcurrentvalue}

\DTMDate{\dtlcurrentvalue}
\endgroup
\end{verbatim}%
yields:

\begingroup
\DTMsetdatestyle{MyDatestyle}
\DTMdate{\dtlcurrentvalue}

\DTMDate{\dtlcurrentvalue}
\endgroup

\hrulefill

This does just save the return-value to the macro \verb|\MyCommand|:

\verb|\DTLgetvalueforkey{\MyCommand}{value}{definitions}{key}{MyFromDate}|\\
\begingroup\footnotesize
\verb|% define the macro "\MyCommand".|\\
\verb|% use the database "definitions".|\\
\verb|% use the column whose name is "value".|\\
\verb|% use the row which in the column "key" holds the item "MyFromData".|
\endgroup

\DTLgetvalueforkey{\MyCommand}{value}{definitions}{key}{MyFromDate}

\verb|\MyCommand| yields: \MyCommand


Now you can use \verb|\MyCommand| within the argument of
\verb|\DTMdate| and \verb|\DTMDate|.
\begin{verbatim}
\begingroup
\DTMsetdatestyle{MyDatestyle}
\DTMdate{\MyCommand}

\DTMDate{\MyCommand}
\endgroup
\end{verbatim}%
yields:

\begingroup
\DTMsetdatestyle{MyDatestyle}
\DTMdate{\MyCommand}

\DTMDate{\MyCommand}
\endgroup

\end{document}

ここに画像の説明を入力してください

関連情報