0

I defined a Tikz macro and I want to use it so the item of an inline itemize is passed as its argument. So far, my solution is this:

\documentclass{article}

\usepackage[inline]{enumitem}
\usepackage{tikz}

\newcommand\itemvalue[1]{
    \tikz[baseline=(o.base)] {
        \node[
        inner xsep=0pt,
        inner ysep = 1pt,
        outer xsep=2pt,
        outer ysep=2pt
        ] (o) at (0,0) {\textcolor{blue!80!black}{\fontsize{10}{16}\textbf{#1}}};
        \draw[color=gray!50, thick] ([xshift=(-1.3)]o.south west) -- ([xshift=(1.3)]o.south east);
    }
}

\begin{document}

\let\olditem\item
\renewcommand\item[1]{\olditem\itemvalue{#1}}
\begin{itemize*}[label={}, labelsep=2em, parsep=2ex]
    \item {First}
    \item {Second}
    \item {Third}
\end{itemize*}

\end{document}

The output looks like this:

Output

This is what I want but I was wondering if there was a way of redefining \item so it reads the full word (not only its first letter). If I remove the braces on each item, the output looks like this:

No braces

This makes sense as far as I can tell how \item works, but I'd like a workaround that doesn't use braces on each item.

Thanks!

1
  • How you want this new-\item work? Does it always gobbles only one word? Commented 1 hour ago

2 Answers 2

1

I didn't get exactly why you want a sequencial index into an itemize environment, you could easily tweak the label with tikzpicture, for example, as what this link shown.

Here below is my proposal to smartly handle the n-rd index with enumerate:

\documentclass{article}
\usepackage[inline]{enumitem}
\usepackage{tikz}
\usepackage{moreenum}
\newcommand*\itemvalue[1]{
    \tikz[baseline=(o.base)] {
        \node[
            inner xsep=0pt,
            inner ysep=1pt,
            outer xsep=2pt,
            outer ysep=2pt,
            text = blue!80!black,
            font = \bfseries\fontsize{10}{16}\selectfont
        ] (o) at (0,0) {#1};
        \draw[color=gray!50, thick] ([xshift=(-1.3)]o.south west) -- ([xshift=(1.3)]o.south east);
    }
}
\usepackage{lipsum}
\begin{document}

\begin{enumerate}[
        label=\protect\itemvalue{\Nthwords*}, 
        labelsep=1em, 
        parsep=2ex
    ]
    \item First\lipsum[1][1]
    \item Second\lipsum[1][1]
    \item Third\lipsum[1][1]
\end{enumerate}

\bigskip

\begin{enumerate*}[label=\protect\itemvalue{\Nthwords*}]
    \item {}
    \item {}
    \item {}
\end{enumerate*}

\end{document}

result

1
  • this is sensible so long as 'first', 'second' etc. aren't just for the example. ;) Commented 12 mins ago
0

\item is redefined within the itemize environment, so \olditem does not have the same definition as \item would.

*** Capturing 'the first word' is fraught and fragile in comparison with capturing a braced group. Caveat emptor ...***

Assumptions re. 'the next word':

  • it begins with the next non-space token;
  • its last token is the token before the first space token following its beginning;
  • the same cat code regime, at least with respect to spaces, is in place when \item is used as when \fancyitem is defined.

Note that an end-of-line counts as a space when normal cat codes are in effect. This means that you must follow every \item by something other than a space or line-break, except for the last \item in the list. Otherwise the following \item will be interpreted as the first word of the previous one.

So if you really want first, second etc., better to use an enumerate with ordinal labels. In case you actually want to pick up arbitrary words, however, that won't work. I that case, I would personally instead use a description or similar and make the words into the labels. But if you prefer to live dangerously or just don't ever make typos in your source code, you can delimit the argument by a space for a (very) simple-minded take on 'first word'.

\documentclass{article}

\usepackage[inline]{enumitem}
\usepackage{tikz}
\pagestyle{empty}
\newcommand\itemvalue[1]{
  \tikz[baseline=(o.base)] {
    \node[
      inner xsep=0pt,
      inner ysep = 1pt,
      outer xsep=2pt,
      outer ysep=2pt
    ] (o) at (0,0) {\textcolor{blue!80!black}{\fontsize{10}{16}\textbf{#1}}};
    \draw[color=gray!50, thick] ([xshift=(-1.3)]o.south west) -- ([xshift=(1.3)]o.south east);
  }
}
\AddToHook{env/itemize*/begin}{%
  \let\olditem\item
  \let\item\fancyitem
}
\newcommand\fancyitem[1]{\olditem\itemvalue{#1}}
\def\fancyitem#1 {\olditem\itemvalue{#1}}
\begin{document}

\begin{itemize*}[label={}, labelsep=2em, parsep=2ex]
  \item First abc
  \item Second
  \item Third def
\end{itemize*}

\end{document}

capturing the first word in a list

Obviously, this won't work if words in you language are delimited by something other than spaces or by nothing at all. It will not work for traditional Chinese, Japanese etc. And, should you follow a word immediately by a punctuation mark, the mark will be included in the 'word'.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.