0

I am just what want to define a tcolorbox with title box environment like this: [I:OBJ_ID_123] due to it is contains underscore.it is very tedious to type_ to show underscore everytime.because my documents contains so many fixed format like I:OBJ_ID_123 .how to make a format just type as plain text without using math symbol mode.just type as [I:OBJ_ID_123].for example

this is demo:

\documentclass[10pt,a4paper]{article}

\usepackage{graphicx}
\usepackage{tcolorbox}
\begin{document}
    \begin{tcolorbox}[halign title=flush right,title=\texttt{[I:OBJ\_ID\_123] }]
        this is demo for how to define this,i need this effect
    \end{tcolorbox}
% start new effect, begin ID:124,125......, it is very hard to type \_ to escape underscore
    \begin{tcolorbox}[halign title=flush right,title=\texttt{[I:OBJ\_ID\_124] }]
    so the second ID begin 124, i need to type [I:OBJ\_ID\_124]
    how to directly to type[I:OBJ_ID_124]
\end{tcolorbox}

\end{document}
3
  • You can define a \newcommand.
    – Karlo
    Aug 20, 2021 at 14:41
  • Please let us understand your problem and post some minimal working code. Thanks
    – MS-SPO
    Aug 20, 2021 at 14:55
  • has updated the question.thanks
    – oneway
    Aug 21, 2021 at 3:23

1 Answer 1

1

Assuming only the digits will change, here's a way to do it by defining a new command \obj:

\documentclass[10pt,a4paper]{article}

\usepackage{graphicx}
\usepackage{tcolorbox}
\begin{document}
    \newcommand{\obj}[1]{I:OBJ\_ID\_#1}

    \begin{tcolorbox}[halign title=flush right,title=\texttt{[I:OBJ\_ID\_123] }]
        this is demo for how to define this,i need this effect
    \end{tcolorbox}
% start new effect, begin ID:124,125......, it is very hard to type \_ to escape underscore
    \begin{tcolorbox}[halign title=flush right,title=\texttt{[I:OBJ\_ID\_124] }]
    so the second ID begin 124, i need to type [I:OBJ\_ID\_124]
%    how to directly to type[I:OBJ_ID_124]
    \end{tcolorbox}

    \begin{tcolorbox}[halign title=flush right,title=\texttt{[\obj{456}] }]
        using a macro (newcommand) to insert the digits
    \end{tcolorbox}
       
\end{document}

Result:

Result

For more details on \newcommand and \newenvironment see here, e.g. to absorb the title and tcolorbox statements: https://en.wikibooks.org/wiki/LaTeX/Macros .

You must log in to answer this question.

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