Questions tagged [strings]
{strings} are sequences of characters (most commonly literal constants). However TeX doesn't have the same concept of strings as other languages, so for questions regarding text in general this tag does not apply. Usually when dealing with {strings} one also uses the primitive {pdfstrcmp} or dedicated packages, such as {xstring} or {expl3}'s string module (l3str).
494
questions
0
votes
1
answer
45
views
Linebreak spacing for saved string
I have a string called \subtitle, and that string comes up at multiple locations.
This string contains a linebreak, so that it shows up better at the front page.
I define this string in main.tex
\...
1
vote
1
answer
400
views
how to auto wrap in path string in latex
I am write path in latex like this:
/data/docker/nginx/volume/conf/conf/conf.d/cert/example.com
but the string is too long for compile to pdf, compiled result like this:
how to handle the path ...
1
vote
1
answer
111
views
Command to change a string on the whole document [duplicate]
I was wondering if it was possible to use a variable within the document to quickly change a string. For example in my cover letter I want to insert the name of a different company but without ...
0
votes
1
answer
281
views
Sorting strings containing Cyrillic and Latin characters at the same time
I have a problem with automatic sorting of lines containing information about authors of several articles, including Russian surname, first name and patronymic, other info, ORCID and e-mail. This ...
3
votes
3
answers
276
views
Expandable macro that extracts the first character of UTF-8/cyrillic string without additional packages
I would like to have an expandable macro that extracts the first (and sometimes the second) character of UTF-8/Cyrillic text strings without using additional packages. No simple solutions from TeX or ...
3
votes
1
answer
134
views
Convert string of rational number to a variable and back [duplicate]
How can I convert LaTeX variables and strings when dealing with rational numbers? I have found many working examples for integers, but none for rational numbers.
\documentclass[12pt]{article}
\begin{...
5
votes
2
answers
609
views
Is there a way to use string manipulations to make macro names?
Bottom line up front: what is a convenient way to input a particular character string into a \newcommand call so it can be manipulated to create multiple macro names? In particular, input (say) ABC ...
3
votes
1
answer
215
views
Rearranging \cite arguments
I have the following requirement for my thesis: If I cite multiple citations, I should cite my papers first.
The names of all my papers start with “my:”.
So I want to define a new command that ...
2
votes
4
answers
682
views
Stringify input - \string on token list
This is a problem I came across and I couldn't find an answer to it on the web so I'm going to do an Q&A-style post here.
The problem
With the tex primitive \string one can turn the following ...
4
votes
3
answers
458
views
Define an expandable function for comparing a token list to a string in LaTeX3
In LaTeX3, I could define a function for comparing a token list to a string
\cs_generate_variant:Nn \tl_if_eq:nnTF { V }
\cs_new_nopar:Npn \module_compare:n #1
{
\tl_if_eq:VnTF \g_some_tl { #1 }...
1
vote
0
answers
277
views
String equality check [closed]
I want to compare 2 strings and perform different tasks based on their results(using if-else loop)
My code is here:
\tab• \hyperlink{new}{New Features, Enhancements, and Changes}\linebreak
\begin{...
0
votes
1
answer
446
views
Finding minimum and maximum values of arguments in function
I am defining a \newcommand called \eventsperiodslist which call some other commands: \event[]{Digits}{} and \period[]{Digits}{Digits}{}
The arguments called "Digits" in \event and \period ...
11
votes
5
answers
1k
views
Test if an argument starts with a particular string
Is there a way in tex to test if an argument starts with some string or not?
And then extract the text that follows that start?
As an example, I want to define a command that makes a text bold if it ...
1
vote
1
answer
41
views
Build a command for article contracté in European languages
I would like to build a command \contraction{<prep>}{<art>} to do the "article contracté" in European languages. For example, I would like to have
\contraction{de}{le}
return du ...
3
votes
1
answer
41
views
Detection if image path contains string fails
For a project I would like to check if my included image is located in the sub-folder graphs or not. To check that I wrote a small MWE:
\documentclass[%
reprint,
amsfonts,
floatfix,
amsmath,amssymb,
...
1
vote
1
answer
494
views
TeX \ifx conditional not working for string comparison
I would like a LaTeX source file to compile in different ways depending on the job name. However, when I run pdflatex mwe with mwe.tex containing
\documentclass{article}
\begin{document}
\ifx{mwe}\...
14
votes
3
answers
513
views
xstring - How to define a macro that removes final punctuation?
Is it possible to create a command to remove final punctuation from a sentence (here to simplify, just remove the final period)?
Thanks to the xstring package, I can remove the final punctuation for a ...
3
votes
1
answer
299
views
How to extract the fontname from \the\font
I know LaTeX doesn't have strings as such but I want to be able to get and save the human readable version of the current font name.
\f@family does not work as expected because it shows the base font ...
6
votes
3
answers
353
views
Split string into part by char position
Explanations
I format a moroccan RIB (Relevé d’identité bancaire for “Bank account number”) to display it as a nice rendering. I need to take each part of the RIB to embrace it with a specific label.
...
31
votes
3
answers
55k
views
ifthenelse equal string comparison fails
I am trying to fix some problems with the accessibility.sty package from www.babs.gmxhome.de
There is one string comparison which always results to false, i.e. the language code definition will not ...
2
votes
2
answers
295
views
Find if a string exists within external files
I'm trying to look for a way to determine if a particular text or string is present in external .tex files. It is like accepting a text input from a user and determining if that text can be found in ...
0
votes
2
answers
105
views
Switch condition (IfStrEqCase) - no match & use inside pgfplot axis
I am trying to learn how to use switch conditions to apply in a document I am creating that contains plots.
Here is an extract to create a MWE :
\documentclass[border=2pt]{standalone}
\usepackage[...
7
votes
3
answers
2k
views
Base64 encoding in LaTeX?
How can we encode some text/string using Base64 encoding in LaTeX? or any alternative solution?
For example, the Base64 encoding of string Latex is bGF0ZXg=.
Here's a representation of what I want to ...
2
votes
3
answers
184
views
LaTeX3 - Test string equality + Star version
I'm looking for some good advice on switching from (La)TeX to LaTeX3
Here is the first questions corresponding to the toy code below.
What is a good way to manage an optional argument with LaTeX3?
...
0
votes
1
answer
51
views
File name comparison with underscore
We have tested \filename{XYZ-2100011} and \include{XYZ-2100011} both input tex file name matched or not, otherwise we passed error messages in the macros.
In my cases how to support input file name ...
3
votes
2
answers
408
views
How do I stop matlab-prettifier thinking print strings are comments?
I am trying to put my code into a Latex document using matlab-prettifier. I am doing this by using \lstinputlisting[style=Matlab-editor]{Trap.m}.
An example of Trap.m (a MATLAB file) is as follows
...
1
vote
1
answer
48
views
File name string comparison
Need to show compilation error if "\filename{XYZ-2100011}" and "\include{XYZ-2100011}" input filename mismatch.
For example, if \filename{ABC-2100012} and \include{XYZ-2100011} ...
4
votes
3
answers
2k
views
Replace a substring
This is actually a follow-up question to Replacing a substring from 6 years ago.
I want to replace a substring in a long string. With \ReplaceStr from the xstring-package this works perfectly fine.
...
1
vote
1
answer
294
views
How can I get a single character from a string?
I'm trying to make a command (macro? not sure about terminology) that takes in as input a string s, a number n, and a character c, and returns true if the nth character of s is c, and false otherwise (...
0
votes
2
answers
531
views
How to multiple underline characters in strings
I need to show examples of border, cover and other regularities on a string and I would like to show that by underlining the characters of a string accordingly. Also I would like to have a larger font ...
11
votes
3
answers
9k
views
LaTeX: Access every character of an string variable
I'm using variables to create strings in that way
\newcommand{\myText}{2014/12/20}
\myText{}
This works great.
Now, I can to access every single character of this string (length is 10), because in ...
3
votes
1
answer
161
views
How to use a string argument to create a macro name and invoke the resulting macro name?
I get part of a macro name as an argument. I want to use that to form a complete macro name and invoke it. How can I do that?
Here is a test case to demonstrate what I am trying to achieve:
\...
0
votes
2
answers
1k
views
"\includegraphics{}" but for .pgf files?
I'm trying to implement a command that makes it easier to put .pgf files in my document (plots from matplotlib), similar to how \includegraphics[scale=...]{...} works for image files. However, because ...
3
votes
1
answer
320
views
ConTeXt: Macro to get character width
Background
Looking to adjust the location of the first letter in a word based on its width.
Problem
The calculation resembles:
\define[1]\StyleChapterChar{%
\cldcontext{string.sub("#1",1,1)}%
}
...
4
votes
5
answers
414
views
Prevent hash doubling with \message
Assume a token sequence:
Token 1: Explicit hash character of category code 6.
Token 2: Explicit 1 of category code 12.
Token 3: Explicit hash character of category code 6.
Token 4: Control word token ...
2
votes
2
answers
284
views
Conditional with multiple conditions, one of which is a string search
Aim
I want a command to write "where #1 is an arbitrary constant", "where #1 are arbitrary constants", "where #1 is an arbitrary function of #2", or "where #1 are ...
2
votes
1
answer
485
views
How to use macro with Journal Abbreviations?
I have downloaded these macros from this page. How to use it? I copy the macros to my file macros.tex. Also, I tried to save to a separate file and use \include{}. In both cases, I obtained an error ...
0
votes
0
answers
643
views
BibTeX -- runaway string warnings?
I get these runaway string warnings which don't seem to stop my LaTeX from compiling but are annoying. How the heck am I supposed to locate a "possible" runaway string which starts at line ...
1
vote
0
answers
53
views
Getting the name of control sequence token - which values of \escapechar besides 32 require special attention?
I'd like to get the name of a control sequence token as sequence of character tokens.
With \relax I'd like to get relax.
The preceeding escape character is to be removed from the result of \string\...
9
votes
2
answers
2k
views
Nest StrLen and ifthenelse commands
Here is a sample of code I am working on:
\documentclass[10pt]{report}
\usepackage{xstring}
\usepackage{ifthen}
\begin{document}
\StrLen{123456}\\ %Prints 6
...
0
votes
2
answers
249
views
How do I compare a specific string to strings from a group using a loop?
I want to compare members of a group of strings to an specific string. Why is this not working ?
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\foreach \n in {x,Enu}{
\begin{frame}
\...
7
votes
4
answers
979
views
Simple implementation of the abs function by getting rid of or by consuming the "-"?
I wish to build a (simple) implementation of abs.
I tried \FPabs but I get a lot of zeros after the decimal point. I could get rid of them with the FP round function, but I don't know the number of ...
1
vote
1
answer
181
views
Write CSV in document with dynamic filename
I'm super new to Latex and I'm trying to do automatic documents that present information regarding each project. Every folder and project has a different name/code and I'd like the document to add a ...
10
votes
6
answers
3k
views
Command to count characters in a specified string
Is there a way to count the number of characters in a specified string?
Suppose I had the following code.
\documentclass{article}
\newcommand{\numchars}[1]{\noindent The string ``#1" has ? ...
5
votes
2
answers
251
views
How to get string length from multi-byte character string when passed as a \def using pdftex
I need to determine the number of printed characters from a multi-byte string. Further, the strings are passed to the routine via \def (ultimately via the readarray process to input a csv file).
I am ...
3
votes
2
answers
367
views
Multibyte StrLen? (StrLen for chinese characters)
I am currently using \StrLen{#1} inside my \newcommand. This works flawlessly for any common string written in latin alphabet.
"Hello" has string length of 5 for example.
Problem is with chinese ...
2
votes
3
answers
109
views
How to convert the last number of the ref command output to string
There is an answer explaining how to convert numbers to text here. But if I use a \ref output in the command \convertdigits, it throws the error Missing number, treated as zero. even if the ref output ...
5
votes
2
answers
4k
views
Convert numbers in string to string
I store some strings in a variable \def\nomVAR{A12Z4E} and I want to create some other command using the content of \nomVAR. LaTeX doesn't accept to declare variable with number in its name. So the ...
3
votes
2
answers
496
views
\pdfstringdef turns accented characters into octal escape sequence
The Question : How to make a glowing text?
@'Symbol 1', interesting, I encapsulated your script into a new command (named '\glow') so I could highlight text just like with '\hl{}'. However the result ...
2
votes
1
answer
169
views
Help to make a faster token replacing macro
I have a macro called \logic which helps me write logical formulas faster by simplifying some common logical symbols. So when I write $\logic{p -> q}$ I obtain $p \to q$.
Here's the code:
\...