繁体   English   中英

LaTeX:每个字母后的空格

[英]LaTeX: space after every letter

我想定义一个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
_______________ 

您可以使用灵魂包进行下划线。 对于单个单词,您可以使用我在下面写的\\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}

对于文本的编程操作,我发现使用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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM