Text Formattingxstring \StrBetween not working with \ref

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
jep
Posts: 3
Joined: Mon Feb 14, 2011 7:07 am

xstring \StrBetween not working with \ref

Post by jep »

Hi,

Could someone explain to me why this isn't working?

Code: Select all

\documentclass{article}

\usepackage{xstring}
\usepackage{enumitem}

\begin{document}

\begin{enumerate}[label=(\arabic*), labelindent=\parindent, leftmargin=*, rightmargin=.5in] 
	\item This is a test premise. \label{Premise-1}
\end{enumerate}

This is the context of the ref to Premise-1: \ref{Premise-1}

% This does not work. The output in \outputtestA is blank.
Test A:
\def \testA{\ref{Premise-1}}
\StrBetween{\testA}{(}{)}[\outputtestA]
\outputtestA

% This works fine.
Test B:
\def \testB{(1)}
\StrBetween{\testB}{(}{)}[\outputtestB]
\outputtestB

\end{document}
It seems to me that Test A should work just like Test B does. If that's not the case... what am I missing and how do I fix it?

Thanks!
Last edited by jep on Wed Feb 16, 2011 9:30 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

jep
Posts: 3
Joined: Mon Feb 14, 2011 7:07 am

Re: xstring \StrBetween not working with \ref

Post by jep »

Here's a clarification of what I'm trying to do here. The \ref points to an enumeration - for example (1). I want to strip the parentheses so that I end up with just 1.

Any help is REALLY appreciated.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

xstring \StrBetween not working with \ref

Post by frabjous »

Why don't you just use enumitem's ref= option?

Code: Select all

\documentclass{article}

\usepackage{enumitem}

\begin{document}

\begin{enumerate}[label=(\arabic*), labelindent=\parindent, leftmargin=*, rightmargin=.5in, ref=\arabic*]
   \item This is a test premise. \label{Premise-1}
\end{enumerate}

This does not have parentheses: Premise \ref{Premise-1}

\end{document}
jep
Posts: 3
Joined: Mon Feb 14, 2011 7:07 am

Re: xstring \StrBetween not working with \ref

Post by jep »

That will work! Thanks!
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

xstring \StrBetween not working with \ref

Post by localghost »

jep wrote:That will work! […]
Then please mark the topic (not the last post) accordingly as written in the Board Rules (to be read before posting).


Best regards and welcome to the board
Thorsten
Post Reply