1

Seeking understanding of how to expand a substring so the value can be evaluated within ifboolexpr from etoolbox package - As a relative newbie to latex (only using it for the past 18 months), I'm finally starting to understand the basics of how it comes together. The issue now is that I'm getting more adventurous with the system, but not having a programming background struggle with some of the concepts and yes I have read the package manuals before posting the question but cannot follow the logic of how to pull it together so any assistance would be great.

I have tried:

  1. the xstring package - not expandable,
  2. substr package - ? no luck
  3. etextools package - supposed to be able to expand but I can't get it to - tried ExpandNext and expandnext but no luck
  4. xparse - review the documentation and put it down - could not even understand it

tried all these packages to achieve my end goal but no luck!.

I can get the substring from a dataset but can't get the etoolbox package to evaluate the result so I can then use it - the result creates errors. I'm guessing its because the substring is not expandable, but I don't know how to get it to expand despite my attempts to do so, even after reading the package documentation :(

The end goal is to have the result available to use by other macros. Basically I'm assessing the original data input and confirming if the data matches my criteria requirement if it does not - then I want to be able to use the revised data as the criteria for the input into Latex. Now before anyone provides a primitive TEX answer, know I'm struggling enough with understanding Latex and using the various packages let alone primitive TEX coding, so if at all possible a response using LATEX packages would be appreciated

Here's my MWE I am showing several packages to demonstrate that I can extract the required string - see results 2-4, however, I have nested result 2 in an ifboolexpr from the etoolbox package but it supplies "no result" as you can see, so the question is how can I get my substring to expand so the etoolbox package can assess it or is there another way?

Apologies if my explanation is long but my first post here.

\documentclass[11pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{etoolbox}
\usepackage{substr}
\usepackage{etextools}

%Custom commands
\newcommand{\nl}{\vspace{1.0\baselineskip} \\}
\newcommand{\str}{Step}
\newcommand{\rcata}{M} %INDI SEX TAG
\newcommand{\rcatb}{dma} %INDI_Relationship Class
\newcommand{\rcatc}{my fathers first wife is my Step mother but is not biologically related to me.} %INDI_Relationship Input string


%START
\begin{document}
\section*{Code Outputs}
First Result: \ifboolexpr{
test {\ifstrequal{\rcata}{M}}%Test INDI Sex
and
test {\ifstrequal{\rcatb}{dmd}}%Test Indi Relationship Class
or
test {\ifstrequal{\rcatb}{dma}}%Test Indi Relationship Class
}
{\DeclareStringFilter\FindSTEP{wife}%See if WIFE in long string
\FindSTEP?.{my fathers first wife is my Step mother but is not biologically related to me.}{imd}{\rcatb}}{\LARGE{This Test Failed}} \normalsize
\\ (trying to expand one test within other tests - but doesn't work) \nl
\paragraph{}
\Large{\textbf{Below are single expansions test only}} \\ \normalsize All are successful by themselves but will not work inside a nested expression - Need to use ``EXPAND' somehow but cannot figure how it has to be done though \nl
Second Result: \DeclareStringFilter\FindSTEP{Step}
\FindSTEP?.{my fathers first wife is my (Step) mother but is not biologically related to me.}{imd - This test was successful}{\rcatb}
\\
using the etextools package \nl
Third Result: \IfSubStringInString{Step}{my fathers first wife is my (Step) mother but is not biologically related to me.}{imd - This test was successful}{This Test Failed} \\ This test uses the substr package with verbatim text only \nl
Forth Result: 
\IfSubStringInString{\str}{\rcatc}{imd - This test was successful}{This Test Failed} \\ This Test uses the substr package but calls a macro - was testing to see if it would do it
\end{document}

enter image description here

  • Should the failing test eventually print imd? – egreg Jan 13 at 20:42
  • HI -egreg, ideally yes – user204824 Jan 13 at 20:44
  • unrelated but size commands do not take an argument \Large{....} will make the rest of the document (or current environmnet) large not the text in {...} – David Carlisle Jan 13 at 20:52
  • Welcome to the site. I am a bit confused. In laymen's terms, what are you seeking to do? Check a long string input for the existence of multiple keywords? Or something else? – Steven B. Segletes Jan 13 at 20:57
  • 1
    @StevenB.Segletes - Ok thanks for the tip :) – user204824 Jan 13 at 22:21
0

You should avoid etextools, really.

The main problem is that \ifstrequal doesn't expand its arguments, but you can make it do it.

\documentclass[11pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{etoolbox}
\usepackage{etextools}

%Custom commands
\newcommand{\str}{Step}
\newcommand{\rcata}{M} %INDI SEX TAG
\newcommand{\rcatb}{dma} %INDI_Relationship Class
\newcommand{\rcatc}{my fathers first wife is my Step mother but 
  is not biologically related to me.} %INDI_Relationship Input string

\begin{document}

\ifboolexpr{
  test {\expandafter\ifstrequal\expandafter{\rcata}{M}}%Test INDI Sex
  and
  test {\expandafter\ifstrequal\expandafter{\rcatb}{dmd}}%Test Indi Relationship Class
  or
  test {\expandafter\ifstrequal\expandafter{\rcatb}{dma}}%Test Indi Relationship Class
}
{\DeclareStringFilter\FindSTEP{wife}%See if WIFE in long string
\FindSTEP?.{my fathers first wife is my Step mother but is not 
  biologically related to me.}{imd}{\rcatb}}{This Test Failed}

\end{document}

A different implementation using the (nonbuggy) expl3 programming environment:

\documentclass[11pt,a4paper]{book}
\usepackage{xparse}

\ExplSyntaxOn
% provide some user level commands
\cs_new_eq:NN \booleanTF \bool_if:nTF
\cs_new_eq:NN \stringequal \str_if_eq_p:ee
\prg_generate_conditional_variant:Nnn \str_if_in:nn { ee } { T,F,TF }
\cs_new_eq:NN \stringinTF \str_if_in:eeTF
\ExplSyntaxOff

%Custom commands
\newcommand{\str}{Step}
\newcommand{\rcata}{M} %INDI SEX TAG
\newcommand{\rcatb}{dma} %INDI_Relationship Class
\newcommand{\rcatc}{my fathers first wife is my Step mother but 
  is not biologically related to me.} %INDI_Relationship Input string

\begin{document}

\booleanTF{
  \stringequal{\rcata}{M}%Test INDI Sex
  &&
  \stringequal{\rcatb}{dmd}%Test Indi Relationship Class
  ||
  \stringequal{\rcatb}{dma}%Test Indi Relationship Class
}
{\stringinTF{\rcatc}{wife}{imd}{\rcatb}}{This Test Failed}

\end{document}

The only change in the logic is that the string to be searched in with \stringinTF is the second argument.

Both codes print

imd

| improve this answer | |
  • thanks egreg - ill give them a go and hopefully get my head around the logic too - many thanks!!! and yes I notice that etextools has some issues, not to mention the documentation is more than a little disjointed, but hey any port in a storm asthe saying goes :) – user204824 Jan 13 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy