0

I'm trying to create a macro which display a list of string and if a string start with '*', it apply specific style (like bold).

So I'm using a foreach and xstring macros but something goes wrong with strange characters displayed.

I made two cases, only the second one is not working but I need to figure out a solution in the configuration of the second case.


Configuration:

MacOS Monterey, shipset M1

LaTeX environnement installed from brew (mactex)


Case 1:

main.tex

\documentclass[10pt,a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[default]{lato}
\usepackage{pgffor}
\usepackage{xstring}

% Command
\newcommand{\simplelist}[1]{%
  \foreach \item in {#1}{
    \item
    \hspace{1cm}
  }
}

\newcommand{\enhancedlist}[1]{%
  \foreach \item in {#1}{%
    \IfSubStr{\item}{*}
      {\textbf{\StrGobbleLeft{\item}{1}}}
      {\item}

    \hspace{1cm}
  }
}

% Document
\begin{document}
\StrGobbleLeft{*item1}{1}\par
\simplelist{item1,*item2,item3}\par
\enhancedlist{item1,*item2,item3}
\end{document}

Build command

latexmk -synctex=1 -interaction=nonstopmode -file-line-error -pdf main

Result

case 1 result


Case 2:

main_with_lib.tex

\documentclass[10pt,a4paper]{custom_library}

\usepackage[T1]{fontenc}    % Example is working if removed
\usepackage[utf8]{inputenc}
\usepackage[default]{lato}

% Document
\begin{document}
\StrGobbleLeft{*item1}{1}\par
\simplelist{item1,item2,*item3}\par
\enhancedlist{item1,item2,*item3}
\end{document}

custom_library.tex

\@ifl@t@r\fmtversion{2018/04/01}{\UseRawInputEncoding}{}
\LoadClass{extarticle}

\RequirePackage{xstring}
\RequirePackage{pgffor}

% Commands
\newcommand{\simplelist}[1]{%
  \foreach \item in {#1}{
    \item
    \hspace{1cm}
  }
}

\newcommand{\enhancedlist}[1]{
  \foreach \item in {#1}{
    \IfSubStr{\item}{*}
      {\textbf{\StrGobbleLeft{\item}{1}}}
      {\item}

    \hspace{1cm}
  }
}

Build command

latexmk -synctex=1 -interaction=nonstopmode -file-line-error -pdf main_with_lib

Result

enter image description here


In case 2, it seems if I remove '\usepackage[T1]{fontenc}', it's working well. But like I said, I'm using this code in a bigger project and I had to keep configuration as it's set in case 2.

Any ideas ? Explanations ? :)

1
  • accented A almost always implies UTF-8 is being mis-interpreted. you have \UseRawInputEncoding which disables LaTeX's encoding support, so bad effects are expected. \UseRawInputEncoding can be used in some legacy contexts to allow "competing" encoding packages, but if used on its own it basically breaks latex Aug 20, 2022 at 21:16

1 Answer 1

3

After {\item} in your definition you have the control character U+2029 (PARAGRAPH SEPARATOR)

Normally if you use that character in LaTeX (here between []):

\documentclass{article}
\usepackage[T1]{fontenc}
\begin{document}

U+2029 PARAGRAPH SEPARATOR [
]
\end{document}

You get

! LaTeX Error: Unicode character 
 (U+2029)
               not set up for use with LaTeX.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.5 U+2029 PARAGRAPH SEPARATOR [

                                   ]
?

however Your document uses \UseRawInputEncoding which disables LaTeX's encoding support so the raw bytes that encode U+2029 are seen as three separate characters in whatever font encoding is current, so

No error but output

enter image description here

If you use OT1 encoding you get output

enter image description here

But it is not really an improvement, it is still typesetting nonsense characters but now warns

Missing character: There is no � in font cmr10!
Missing character: There is no � in font cmr10!
Missing character: There is no � in font cmr10!

as OT1 encoding has no accented characters.


So firstly you want to remove the U+2029 from the line

      {\item}


(you may find it easiest to delete the line and re-type)

Then remove

\@ifl@t@r\fmtversion{2018/04/01}{\UseRawInputEncoding}{}

which can never help here.

Not related to the error but I would not use \item as your local loop variable, it is a standard latex command so confuses anyone debugging this.

1
  • Thank you for the answer ! It worked. I removed '\@ifl@t@r\fmtversion{2018/04/01}{\UseRawInputEncoding}{}' and retype '{item}' line. Now, I just have to figure out how to see (paragraph separator) in my editor to avoid further issue. Aug 22, 2022 at 8:48

You must log in to answer this question.

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