반환된 명령 값을 다른 함수에 전달

반환된 명령 값을 다른 함수에 전달

실수로 명령 값을 다른 함수에 전달하려고 합니다. 예를 \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-calc이 책을 쓴 작가에게서 나온 것입니다.데이터 도구패키지,니콜라 탤벗 박사.

이러한 패키지를 사용하면 원하는 대로 새로운 날짜 스타일을 쉽게 정의할 수 있습니다.

\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}

여기에 이미지 설명을 입력하세요

관련 정보