LaTeX:每个字母后有空格

发布于 2024-09-27 23:26:14 字数 313 浏览 0 评论 0原文

我想定义一个 LaTeX 命令,在每个字母后插入一个空格。

那么,如果我添加

\addSpaces{someText}

结果应该是

s o m e T e x t 

我怎样才能实现这一目标?

背景:我希望每个字母都带有下划线,但字母之间应该分隔线:

s o m e T e x t 
_ _ _ _ _ _ _ _

NOT:
s o m e T e x t
_______________ 

I want to define a LaTeX command that inserts a space after every letter.

So, If I add

\addSpaces{someText}

the result should be

s o m e T e x t 

How could I achieve this?

Background: I want each letter to be underlined, but the line should be separated between the letters:

s o m e T e x t 
_ _ _ _ _ _ _ _

NOT:
s o m e T e x t
_______________ 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧伤慢歌 2024-10-04 23:26:14

您可以使用 soul 包 进行下划线。对于单个单词,您可以使用我在下面编写的 \addspaces 宏。 (宏将吞掉单词之间的空格。一个简单的解决方法是使用 \quad 来增加单词之间的空格。)

\documentclass{article}

\usepackage{soul}% provides underlining

\makeatletter% since we're using a macro containing @
\newcommand{\addspaces}[1]{%
  \@tfor\letter:=#1\do{%
    \ul{\letter}\space
  }%
}
\makeatother% resets @ to its original meaning

\begin{document}

% Works fine for single words
\addspaces{Spaces}

% Note that spaces in between words aren't preserved -- use \quad to add extra space.
\addspaces{Spaced\quad and\quad underlined.}

\end{document}

You can use the soul package for underlining. For single words, you can use the \addspaces macro I wrote below. (The macro will swallow the space between words. A simple workaround is to use \quad to increase the space between the words.)

\documentclass{article}

\usepackage{soul}% provides underlining

\makeatletter% since we're using a macro containing @
\newcommand{\addspaces}[1]{%
  \@tfor\letter:=#1\do{%
    \ul{\letter}\space
  }%
}
\makeatother% resets @ to its original meaning

\begin{document}

% Works fine for single words
\addspaces{Spaces}

% Note that spaces in between words aren't preserved -- use \quad to add extra space.
\addspaces{Spaced\quad and\quad underlined.}

\end{document}
雨夜星沙 2024-10-04 23:26:14

对于文本的编程操作,我发现使用 perltex 定义 perl 函数来执行代码然后编译文档要容易得多。请参阅此处的 CTAN

这是一个快速而肮脏的过程。

\documentclass{article}
\usepackage{perltex}

\perlnewcommand{\ulspace}[1]{
$input = shift;
$input =~ s/(\w)/\\underline\{\1\} /g;
return $input;
}

\begin{document}

\ulspace{Hello World}

\end{document}

编译:

perltex --latex=pdflatex myfile.tex

For programmatic manipulation of text I find it much easier to use perltex to define a perl function to do the code and then compile the document. See CTAN here.

Here is a quick and dirty.

\documentclass{article}
\usepackage{perltex}

\perlnewcommand{\ulspace}[1]{
$input = shift;
$input =~ s/(\w)/\\underline\{\1\} /g;
return $input;
}

\begin{document}

\ulspace{Hello World}

\end{document}

Compile with:

perltex --latex=pdflatex myfile.tex
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文