LaTeX forum ⇒ Text Formattingcoolstr Topic is solved

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

coolstr

Postby kabenyuk » Sun Feb 03, 2019 12:07 pm

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

  1. \documentclass[10pt]{article}
  2. \usepackage{coolstr}
  3.  
  4. \newcommand{\simv}[2]{
  5. \ifstrchareq{#1}{#2}{A}{10}{
  6. \ifstrchareq{#1}{#2}{B}{11}{
  7. \ifstrchareq{#1}{#2}{C}{12}{
  8. \substr{#1}{#2}{1}}}}}
  9.  
  10. \begin{document}
  11.  
  12. \simv{C2A3B}{1}
  13. \simv{C2A3B}{2}
  14. \simv{C2A3B}{3}
  15. \simv{C2A3B}{4}
  16. \simv{C2A3B}{5}
  17.  
  18. \end{document}


However, instead of 12210311 I get this: 12 2 10 3 11
coolstr_expl.pdf
(9.41 KiB) Downloaded 7 times

For some reason, there are extra spaces.
What am I doing wrong?
Thank!
Best regards!

kabenyuk

User avatar
Stefan Kottwitz
Site Admin
Posts: 9285
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Sun Feb 03, 2019 5:17 pm

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 %:

  1. \documentclass[10pt]{article}
  2. \usepackage{coolstr}
  3.  
  4. \newcommand{\simv}[2]{%
  5. \ifstrchareq{#1}{#2}{A}{10}{%
  6. \ifstrchareq{#1}{#2}{B}{11}{%
  7. \ifstrchareq{#1}{#2}{C}{12}{%
  8. \substr{#1}{#2}{1}}}}}
  9.  
  10. \begin{document}
  11.  
  12. \simv{C2A3B}{1}%
  13. \simv{C2A3B}{2}%
  14. \simv{C2A3B}{3}%
  15. \simv{C2A3B}{4}%
  16. \simv{C2A3B}{5}
  17.  
  18. \end{document}


Stefan
Site admin

kabenyuk
Posts: 2
Joined: Sun Feb 03, 2019 10:09 am

Postby kabenyuk » Sun Feb 03, 2019 6:24 pm

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


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 12 guests