1

In the following snippet of LaTeX package (sublime text 3) every time I enter a: Space, . (dot), ?, *, #, Is replaced by "_" character in the part \label{sec:*****} and % section ***** (end). Also replaces capital letters to lowercase. Here the snippet:

<snippet>
<content><![CDATA[
\section{${1:section name}} % (fold)
\label{sec:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3)/g}}}
${0:$TM_SELECTED_TEXT}
% section $2 (end)
]]></content>
    <tabTrigger>sec</tabTrigger>
    <scope>text.tex.latex</scope>
    <description>Section</description>
</snippet>

My question is: how can I change? the snippet to replace accented vowel by vowel without tilde, ie, if I use the snippet the result is:

\section{acción además menú aquí acné} % (fold)
\label{sec:acción_además_menú_aquí_acné}

% section acción_además_menú_aquí_acné (end)

but I want to get the following:

\section{acción además menú aquí acné} % (fold)
\label{sec:accion_ademas_menu_aqui_acne}

% section accion_ademas_menu_aqui_acne (end)
rral
  • 554
  • 3
  • 20

1 Answers1

2

You can do this by manually specifying the characters to find and what to replace them with. This is because ST unfortunately doesn't seem to support the POSIX character equivalents.

Using the following snippet:

<snippet>
<content><![CDATA[
\section{${1:section name}} % (fold)
\label{sec:${2:${1/(?i:(á)|([éę])|(í)|(ó)|(ú)|(ń))|\\\w+\{(.*?)\}|\\(.)|(\w)|([^\w\\]+)/(?{10}_:\L$7$8(?1a:)(?2e:)(?3i:)(?4o:)(?5u:)(?6n:)$9)/g}}}
${0:$TM_SELECTED_TEXT}
% section $2 (end)
]]></content>
    <tabTrigger>sec</tabTrigger>
    <scope>text.tex.latex</scope>
    <description>Section</description>
</snippet>

typing sec Tab and typing/pasting in acción además menú aquí acné ńę, for example, will result in:

\section{acción además menú aquí acné_ńę} % (fold)
\label{sec:accion_ademas_menu_aqui_acne_ne}

% section accion_ademas_menu_aqui_acne_ne (end)

For more information on the replacement format syntax, see http://www.boost.org/doc/libs/1_56_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

Keith Hall
  • 15,362
  • 3
  • 53
  • 71
  • Nice job, I didn't think regex could handle multiple possible substitutions like that. – MattDMo Aug 05 '16 at 17:50
  • Dear @keith-hall, I'm currently working with visual studio code. How could I make the same snippet for this editor? Thank you – rral Sep 18 '21 at 21:25
  • @rral, not sure, I suggest asking a new question with the appropriate tags :) – Keith Hall Sep 22 '21 at 20:00