2

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
4
  • 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
5
% arara: pdflatex

\documentclass{article}
\newcommand*{\var}{2}
\newcommand*{\x}{5}

\begin{document}
    The content of \verb|\var| is \var

    $\var+\x = \the\numexpr\var+\x\relax$
\end{document}

enter image description here


Edit:

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

% arara: pdflatex

\documentclass{article}
\newcounter{mycounter}

\begin{document}
    \setcounter{mycounter}{42}
    \themycounter{} My Section Starting where I Want
    \stepcounter{mycounter}

    \themycounter{} And Here Comes the Next Section 
\end{document}

enter image description here

3
  • 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.