2

How can I make the variable for non-Latex user, for example, using the \newcommand{}{} with parameters? For example, I want the user change only the word in newcommand description and it will change in whole document automatically?

\newcommand{\R}{My system}
...
\section{Introduction}
Here I would like to introduce \( \R \)
...
   \begin{table}[]
       \centering
       \begin{tabular}{c|c}
           \( \R \) &  \\
                    & 
       \end{tabular}
       \caption{Caption}
       \label{tab:my_label}
   \end{table}

This doesn't work with Russian letters (\usepackage[russian,english]{babel} and \selectlanguage{russian} is added and in usage)

Ok, posting the full example where I don't get anything (blank space instead of russian word):

\documentclass{article}
%\documentclass{ICD}
\usepackage[T2A,T1]{fontenc}

\usepackage[utf8]{inputenc}
\usepackage{multicol}
%\usepackage[russian,english]{babel}
\usepackage[russian]{babel}
\usepackage{multirow}   %для таблиц со слиянием столбцов и строк
\usepackage{amsthm}
\usepackage{array}      %для таблиц с заданной шириной столбца
\usepackage{float}
\usepackage[table]{xcolor}
%\setlength{\arrayrulewidth}{1mm}
%\setlength{\tabcolsep}{18pt}
%\renewcommand{\arraystretch}{2.5}
%\newcolumntype{s}{>{\columncolor[HTML]{AAACED}} p{3cm}}
%\arrayrulecolor[HTML]{DB5800}

\ProcessOptions

\begin{document}
%\hoffset = 20pt
%\maketitle
\selectlanguage{russian}


\tableofcontents


\newcommand{\Mysyst}{ \begin{center} \selectlanguage{russian} система \end{center}}

 \section{Introduction}
    Here I would like to introduce \( \Mysyst \)
    ...
       \begin{table}[]
           \centering
           \begin{tabular}{c|c}
               \( \Mysyst \) &  \\
                        & 
           \end{tabular}
           \caption{Caption}
           \label{tab:my_label}
       \end{table}


\end{document}
5
  • 1
    Where do you want to add the non-ASCII characters? In the name of the macro, it's impossible with standard pdflatex (maybe in LuaLaTeX). In the content, there is no problem. Can you post a full example showing the problem? tex.meta.stackexchange.com/questions/6255/…
    – Rmano
    Commented Mar 16, 2022 at 14:08
  • BTW. in your example \R expands to My system and then it's used in math mode --- which clearly ins't. Are you sure you really do not want italics?
    – Rmano
    Commented Mar 16, 2022 at 14:14
  • 2
    Still: this is not an example. Put a code that I can copy, paste to my editor, and run compile. Like my code in the answer. (and btw, it's better if you prepare your MWE and post another answer). Please read tex.meta.stackexchange.com/questions/228/… answers: it will take a bit of time, but you'll gain it back in no time
    – Rmano
    Commented Mar 16, 2022 at 14:28
  • @Rmano oh, thank you! reading it. I just deleted the files that I input in my code. Gonna improve and make MWE. But I think something wrong with cyrillic libraries usage in my code, because it says that "\cyrs invalid in math mode" . Studying all this. And many thanks for your help! Commented Mar 16, 2022 at 14:35
  • Yes, you can't use cyrillic characters in math mode. Again, are you sure you need math mode? That is for math formulas, nothing else. If you prepare an example that fails, and explains what you are trying to obtain, you'll have an answer. Notice that in my code, trying to put ñ in a math formula will also fail.
    – Rmano
    Commented Mar 16, 2022 at 14:45

1 Answer 1

6

New answer after the MWE

  1. You are using \( and \) delimiter here --- they enter mathematical mode. I do not read russian, but I think that система is not a formula, isn't it? If you want to typeset it in italic or slanted) font, use \textit (or \emph, or \textsl, depending on the objective). In math mode you can have just formulas: https://www.learnlatex.org/en/lesson-10

  2. I do not get what you want to obtain with the \begin{center}...\end{center} there. In the tabular, the text is already centered. And there is no sense in "centering" inside a paragraph, like you are trying to do in the first line of text.

  3. \ProcessOptions is for package creators, not user, avoid it. And you have to specify where you want your floating, so I added [ht] (you should have had a warning).

Correct those and you have:

output of the corrected MWE

\documentclass{article}
\usepackage[T2A,T1]{fontenc}

\usepackage[utf8]{inputenc}
\usepackage{multicol}
\usepackage[russian]{babel}
\usepackage{multirow}   %для таблиц со слиянием столбцов и строк
\usepackage{amsthm}
\usepackage{array}      %для таблиц с заданной шириной столбца
\usepackage{float}
\usepackage[table]{xcolor}


\begin{document}
\selectlanguage{russian}


\tableofcontents

% Additional braces to confine the effect of selectlanguage
\newcommand{\Mysyst}{{\selectlanguage{russian} система}}

 \section{Introduction}
    Here I would like to introduce \emph{\Mysyst}
    ...
       \begin{table}[ht]
           \centering
           \begin{tabular}{c|c}
               \Mysyst &  \\
                        & 
           \end{tabular}
           \caption{Caption}
           \label{tab:my_label}
       \end{table}

\end{document}

Original answer

Just to show you why an MWE is really necessary in LaTeX to understand the problem: this snippet:

\documentclass[a4paper,11pt]{article}
\usepackage[spanish, english]{babel}
\newcommand{\R}{The letter ``ñ''} 
\begin{document}
\section{Introduction}
Here I would like to introduce \emph{\R}

   \begin{table}
       \centering
       \begin{tabular}{c|c}
           \emph{\R} &  \\
                    & 
       \end{tabular}
       \caption{Caption}
       \label{tab:my_label}
   \end{table}

\end{document}

works perfectly, giving

output from the above snippet

...so we are at a loss to say where your problem really is.

7
  • Yeah, sure i'm lost too... For example, this code inputs the russian word : \newcommand{\FirstBlock}{ \begin{center} \selectlanguage{russian} система \end{center}} Commented Mar 16, 2022 at 14:18
  • 4
    Just prepare a simple MWE like mine showing your problem, instead of posting non-compilable snippet, and somebody will find the issue! (And chances are that, while creating the MWE, you'll find the error by yourself. It happens to me all the time)
    – Rmano
    Commented Mar 16, 2022 at 14:21
  • 1
    ...and you can't use \begin{center}....\end{center} in a tabular c column, or \emph... this is creating paragraphs. If you put this in your example, together with the error text, the community can help. Otherwise, it's a game of guessing
    – Rmano
    Commented Mar 16, 2022 at 14:22
  • 1
    I would suggest going throu learnlatex.org --- it's worth the while, and it will clarify some concepts that will help you a better experience with LaTeX
    – Rmano
    Commented Mar 16, 2022 at 16:14
  • 1
    thanks a lot, learnlatex.org even has free lessons and fast compiler with text processor! Actually the mathematical mode was the reason of getting nothing when I used ( and ) . Furthermore I\ve deleted the \begin{center}...\end{center} following your advice. I appreciate your help a lot! Commented Mar 17, 2022 at 9:18

You must log in to answer this question.

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