Text Formattingcoolstr

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
kabenyuk
Posts: 2
Joined: Sun Feb 03, 2019 10:09 am

coolstr

Post by kabenyuk »

Hi. dear frend!
This is my question.
I'm trying to use the coolstr package. Like this.
coolstr_expl.tex
(286 Bytes) Downloaded 157 times

Code: Select all

\documentclass[10pt]{article}
\usepackage{coolstr}

\newcommand{\simv}[2]{
     \ifstrchareq{#1}{#2}{A}{10}{
      \ifstrchareq{#1}{#2}{B}{11}{
       \ifstrchareq{#1}{#2}{C}{12}{
        \substr{#1}{#2}{1}}}}}

\begin{document}

\simv{C2A3B}{1}
\simv{C2A3B}{2}
\simv{C2A3B}{3}
\simv{C2A3B}{4}
\simv{C2A3B}{5}

\end{document}
However, instead of 12210311 I get this: 12 2 10 3 11
coolstr_expl.pdf
(9.41 KiB) Downloaded 161 times
For some reason, there are extra spaces.
What am I doing wrong?
Thank!
Best regards!

kabenyuk

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

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

coolstr

Post by Stefan Kottwitz »

Hi kabenyuk,

welcome to the forum!

The end of the line is considered as a space. In the document code, If a word is at the end of a line and another word follows on the next line, there will be a space in the output between the words. Since line ends are considered as a space, macro authors very often add a percent sign at the end of the line to comment that space out. That's how you can fix it, comment out the line end by %:

Code: Select all

\documentclass[10pt]{article}
\usepackage{coolstr}

\newcommand{\simv}[2]{%
\ifstrchareq{#1}{#2}{A}{10}{%
\ifstrchareq{#1}{#2}{B}{11}{%
\ifstrchareq{#1}{#2}{C}{12}{%
\substr{#1}{#2}{1}}}}}

\begin{document}

\simv{C2A3B}{1}%
\simv{C2A3B}{2}%
\simv{C2A3B}{3}%
\simv{C2A3B}{4}%
\simv{C2A3B}{5}

\end{document}
Stefan
LaTeX.org admin
kabenyuk
Posts: 2
Joined: Sun Feb 03, 2019 10:09 am

coolstr

Post by kabenyuk »

Thank you so much, Stefan. You helped me a lot.
Post Reply