To have something equivalent to echo of the shell. For instance in .tex file we have:

 \def \var{2}

    The content of var is $var

How to edit the tex file in such a way we have as output:

The content of var is 2?

Especially, can we perform arithmetic operations under latex? Say

var = var + x
  • Related: tex.stackexchange.com/q/30081 – LaRiFaRi Jan 12 '15 at 9:23
  • (La)TeX can calculate stuff, but it is meant for typesetting. Depending on what you want to do, Lua would be the better alternative. – Johannes_B Jan 12 '15 at 9:28
  • In fact, I need to enumerate some sections but without using itemize or the like. I need to add a number before some sections and this number needs to increment. – Courier Jan 12 '15 at 9:31
  • 1
    I guess you are looking for section and should not implement stuff on your own. If you really want to do it yourself, stepcounter and refstepcounter are the commands to use with LaTeX2e. – Johannes_B Jan 12 '15 at 9:40
% arara: pdflatex


    The content of \verb|\var| is \var

    $\var+\x = \the\numexpr\var+\x\relax$

enter image description here


In your comment to your question, you ask something quite different. This could be done like this:

% arara: pdflatex


    \themycounter{} My Section Starting where I Want

    \themycounter{} And Here Comes the Next Section 

enter image description here

  • This is exactly what I was looking for. Thanks a lot! – Courier Jan 12 '15 at 9:50
  • Should I reformulate my question? – Courier Jan 12 '15 at 9:51
  • @polar Glad I could help. If you think, this post will help others in future, you could rewrite your question a bit. Or just change the title. Like it stands now, it will be a bit confusing. Don't know... if you think, everything has been answered already on this site, you could also think about deleting it. Whatever you want. – LaRiFaRi Jan 12 '15 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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