TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I still struggle with the expansion of Latex. I try to calculate the a real number from a date format and put this into a macro \value. I need to expand the command with \edef because I plan to use the value as a parameter in pgfplots.






\dateconvert{2010-07-01} %works

\value %does not work: Use of \value doesn't match its definition


Calling \dateconvert directly works. However, when I try to copy the result into \value, it fails.

share|improve this question
Since \dateconvert performs various assignments it’s not fully expandable. So you can’t use it in an \edef context. By the way, if \dateconvert were fully expandable you would have to write \edef\value{\dateconvert{2010-07-01}}. – mhp Sep 21 '12 at 7:08
@MartinL. In addition to the comments above, \value is a LaTeX kernel macro, so it's a bad idea to redefine it: you should pick a different name! – Joseph Wright Sep 21 '12 at 7:17
up vote 3 down vote accepted

Is this procedure right for you?




\x{} and \y{}


2010.5 and 2010.16666
share|improve this answer
I get an error when compiling your MWE (! Undefined control sequence \pgfkeys). This error disappears when using \usepackage{pgf} instead of \usepackage{pgfmath}. – mhp Sep 21 '12 at 7:25
Obviously \pgfmathsetmacro solved the problem. If I would use \edef instead of \pgfmathsetmacro, this would not work anymore. My question now: Since \pgfmathsetmacro only works for numbers, how would I solve the problem if the command would not set a number but a string. – Martin L. Sep 21 '12 at 7:57
@MartinL. That's somewhat different to the question here. Perhaps post a second question, linking to this and show the context of what you want to do. If all you want to do is store a string, why not just \def\myvalue{<string>}? – Joseph Wright Sep 21 '12 at 8:10

The error you get arises from the fact that


defines \value as a macro which must be immediately followed by \dateconvert and which is replaced by the text 2012-07-01. As mentioned in comments, you'd need


to set \value in the way you intend, but this requires that \dateconvert is expandable. As it performs an assignment, this is not the case (and indeed pgfmath is not expandable at all).

One relatively simple approach is


\DeclareExpandableDocumentCommand { \dateconvert } { m }
  { \dateconvert:n {#1} }
\cs_new:Npn \dateconvert:n #1
  { \__dateconvert:w #1 \q_stop }
\cs_new:Npn \__dateconvert:w #1 - #2 - #3 \q_stop
  { \fp_eval:n { #1 + ( #2 - 1 ) / 12 + ( #3 - 1 ) / 365 } }



\dateconvert{2010-07-01} %works


This works using the expandable LaTeX3 FPU, and a simple set up for the date parsing: from the question, it's not clear now robust this needs to be. I've renamed \value to \myvalue as \value is a LaTeX kernel command, and you really should not use this name.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.