2

What would be the procedure to see the value of a latex variable such as \baselinestretch and \parskip.

Macros, such as \baselinestretch): \show\baselinestretch and for a dimension such as \parskip): \showthe\parskip have been suggested to me.

Are the above commands that would be displayed in the latex document ?

6
  • 1
    If you quote verbatim the comment of another user, it would be nice if you would mention their username and add a link to tex.stackexchange.com/questions/693238/… Aug 11, 2023 at 22:54
  • I am not so smart and have just started using this thing.
    – Veak
    Aug 11, 2023 at 23:13
  • What do I have to provide and hew would the macros be used ?
    – Veak
    Aug 11, 2023 at 23:15
  • It is not clear what you are asking, just put \showthe\parskip and it will show the value in the log file. Aug 11, 2023 at 23:19
  • @Agava In case you wish to link to a comment: For doing this you need to obtain its url: With most browsers right-clicking the time-stamp of a comment opens up a context-menu where you can select the action of copying the url of that link/comment to clipboard. Aug 11, 2023 at 23:29

2 Answers 2

2

What would be the procedure to see the value of a latex variable such as \baselinestretch and \parskip.

Macros, such as \baselinestretch): \show\baselinestretch and for a dimension such as \parskip): \showthe\parskip have been suggested to me.

Are the above commands that would be displayed in the latex document ?

It depends on the kind of variable and on where you wish to see the value of the variable:

Commands are to occur in the .tex-input-file/in the file containing the .tex source for your document.

As \show is mentioned while \show does actually not refer to the value of a "variable" but does refer to the meaning of a token, let's point out that the meaning of a token is not the same as the value of a "variable".

The term meaning of a token refers to information about the kind of which the token in question is, plus additional information depending on the kind of token.
I.e., whether the token in question denotes a macro or a register or a primitive or a character or ... .
In case of the token being a macro you also get information about predicates like \long, \outer, \protected and about parameter text and replacement text.

The command \show⟨token⟩ causes TeX to write information about the meaning of the token in question to the console and to the .log-file.

The command \meaning⟨token⟩ causes TeX to append character tokens of category 12(other), except spaces which are of category 10(space), to the token stream so that the sequence of these character tokens denotes the information about the meaning of the token in question. Further processing of these character tokens may lead to typesetting information about the meaning of the token in question to the output-file/.pdf-file which TeX is about to produce.

The term "variable" was officially introduced into TeX-jargon by the developers of LaTeX3/expl3.

Outside LaTeX3/expl3 the concept "variable" is rather vague in TeX/LaTeX.

Outside LaTeX3/expl3 "value of variable" may denote, e.g.,

  • the value stored in a register,
  • the value of a TeX-parameter,
  • the replacement text of a parameterless macro in case that macro serves as "variable" and thus is defined so that the tokens forming its replacement text can be considered the value of the variable,
  • the value of a LaTeX-counter defined via \newcounter.

If "variable" is about a register or a TeX-parameter or the like :

The command \showthe⟨token⟩ causes TeX to write information about the meaning of the value of the register/TeX-parameter denoted by ⟨token⟩ to the console and to the .log-file.

The command \the⟨token⟩ causes TeX to append character tokens of category 12(other), except spaces which are of category 10(space), to the token stream so that the sequence of these character tokens denotes the information about the value of the register/TeX-parameter denoted by ⟨token⟩. Further processing of these character tokens may lead to typesetting information about the value of the register/TeX-parameter in question to the output-file/.pdf-file which TeX is about to produce.

If "variable" is about a parameterless macro whose expansion is considered to be the value of the variable:

The command \message{⟨token⟩} causes TeX to write the "value" of the "variable" denoted by the macro ⟨token⟩ to the console and to the .log-file.

The ⟨token⟩ itself, i.e., the command ⟨token⟩, causes TeX to append to the token stream the tokens that form the replacement text of the macro/variable denoted by ⟨token⟩.
As that replacement text is considered to be the value of the "variable" denoted by the macro token ⟨token⟩, further processing of the tokens forming that replacement text may lead to typesetting information about the value of the "variable" in question to the output-file/.pdf-file which TeX is about to produce.

In order to prevent further expansion of the tokens forming the replacement text of ⟨token⟩, you can do s.th. like
\detokenize\expandafter{⟨token⟩} .

If "variable" is about a LaTeX-counter defined via \newcounter, then, e.g., \number\value{⟨counter⟩} and \the\numexpr\value{⟨counter⟩}\relax can be used for obtaining a set of character tokens of category 12(other) denoting the value of that counter.

For writing to console and .log-file you can wrap that between \message{ and }.

7
  • Printing them in the output document would be most convenient.
    – Veak
    Aug 12, 2023 at 0:15
  • Why the decision to print macro:->1.3 all lumped together with -> rather than the more appealing look of 0.0pt plus 1.0pt ? Simple is better than fancy when showing environment parameters, even for macros.
    – Veak
    Aug 12, 2023 at 0:23
  • 2
    @Agava the macro prefix is part of the meaning not just cosmetic display. sometimes it will say long macro or protected macro, or the character, or a fixed list of other prefixes that tell you what kind of token it is Aug 12, 2023 at 7:49
  • @Agava That's because there are several kinds of tokens in TeX. Macros are just one of them. \meaning also provides info abut the kind of token. It is possible to check whether the result of applying \meaning has a leading macro: and in case the parameter-text does not contain some -> remove everything till the first ->. Aug 13, 2023 at 13:01
  • @Agava Actually \meaning is of rather limited use: \meaning delivers character tokens of category 12(other), except spaces which have category 10(space). Therefore \meaning cannot be used reliably for reproducing a macro's definition as info about how the replacement-text was tokenized and what categories character-tokens actually had is lost. Aug 13, 2023 at 13:01
2

It depends on what kind of “variable” you want to show the value of.

Here's a fairly general method; however, primitive parameters should be dealt with case-by-case, so I only provide a method that will work in most cases.

\documentclass{article}

\ExplSyntaxOn

\NewDocumentCommand{\showvariable}{sm}
 {
  \IfBooleanTF { #1 }
   {
    \exp_args:Nc \agava_showvar:N { #2 }
   }
   {
    \agava_showvar:N #2
   }
 }

\cs_new:Nn \agava_showvar:N
 {
  \texttt{\token_to_str:N #1\unskip} ~
  \bool_case:n
   {
    { \token_if_macro_p:N #1 } { #1 ~ (macro) }
    { \token_if_chardef_p:N #1 } { \int_eval:n { #1 } ~ (chardef) }
    { \token_if_mathchardef_p:N #1 } { \int_eval:n { #1 } ~ (mathchardef) }
    { \token_if_dim_register_p:N #1 } { \dim_eval:n { #1 } ~ (dimension) }
    { \token_if_skip_register_p:N #1 } { \skip_eval:n { #1 } ~ (skip) }
    { \token_if_primitive_p:N #1 } { \the#1 ~ (primitive) }
   }
 }

\ExplSyntaxOff

\begin{document}

\showvariable{\baselinestretch}

\showvariable{\baselineskip}

\showvariable{\normalbaselineskip}

\showvariable{\textwidth}

\showvariable{\parindent}

\showvariable*{@M}

\linespread{1.2}\selectfont

\showvariable{\baselinestretch}

\end{document}

enter image description here

No output in the first case, because the default initial value of \baselinestretch is empty.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .