summaryrefslogtreecommitdiff
path: root/support/latexindent/LatexIndent/DoubleBackSlash.pm
blob: 8b8be3e25ece691bfead2448b2fa9c5f24a9432d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package LatexIndent::DoubleBackSlash;
#	This program is free software: you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation, either version 3 of the License, or
#	(at your option) any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	See http://www.gnu.org/licenses/.
#
#	Chris Hughes, 2017
#
#	For all communication, please visit: https://github.com/cmhughes/latexindent.pl
use strict;
use warnings;
use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/;
use LatexIndent::Tokens qw/%tokens/;
use Exporter qw/import/;
our @EXPORT_OK = qw/dodge_double_backslash un_dodge_double_backslash/;

# some code can contain, e.g
#       cycle list={blue,mark=none\\},
# see test-cases/texexchange/29293-christian-feuersanger.tex
#
# This is problematic, as the argument regexp won't count the right } because it has a 
# backslash immediately infront of it!
sub dodge_double_backslash{
    my $self = shift;

    ${$self}{body} =~ s/(?:\\\\(\{|\}|\]))/$tokens{doubleBackSlash}$1/sg;
    return;
}

# this routine replaces the token with the \\\\
sub un_dodge_double_backslash{
    my $self = shift;

    ${$self}{body} =~ s/$tokens{doubleBackSlash}/\\\\/sg;
    return;
}

1;