cmhughes / latexindent.pl

Perl script to add indentation (leading horizontal space) to LaTeX files. It can modify line breaks before, during and after code blocks; it can perform text wrapping and paragraph line break removal. It can also perform string-based and regex-based substitutions/replacements. The script is customisable through its YAML interface.
GNU General Public License v3.0
884 stars 84 forks source link

latexindent changes characters with accents #411

Closed raziel408 closed 1 year ago

raziel408 commented 1 year ago

Please provide the following when posting an issue:

original .tex code

\documentclass[spanish]{report}

\usepackage[latin1]{inputenc} \usepackage[spanish]{babel} \usepackage[all]{xy}

\begin{document}

\chapter{Introducción}

\end{document}

yaml settings

Please paste your YAML settings (if any) here

actual/given output

\documentclass[spanish]{report}

\usepackage[latin1]{inputenc} \usepackage[spanish]{babel} \usepackage[all]{xy}

\begin{document}

\chapter{Introducci\xF3n}

\end{document}

desired or expected output

\documentclass[spanish]{report}

\usepackage[latin1]{inputenc} \usepackage[spanish]{babel} \usepackage[all]{xy}

\begin{document}

\chapter{Introducción}

\end{document}

anything else

It's changing the ó in Introducción for \xF3. I looked for a solution or a possible configuration that would solve it in the documentation. But didn't find any. Any help to solve this would be appreciated.

cmhughes commented 1 year ago

Many thanks for this, I'll look at it soon hopefully, no later than the weekend.

cmhughes commented 1 year ago

I'm unable to replicate your results.

I'm on Linux Ubuntu, and I receive the output

\documentclass[spanish]{report}

\usepackage[latin1]{inputenc}
\usepackage[spanish]{babel}
\usepackage[all]{xy}

\begin{document}

\chapter{Introducción}

\end{document}

Can you let me know details of what your set up is?

raziel408 commented 1 year ago

I'm on linux mint 21. I used emacs with apheleia mode. But I just tested it from the console and had the same result.

cmhughes commented 1 year ago

It sounds like this might be to do with your operating system

On Sat, 21 Jan 2023, 14:00 raziel408, @.***> wrote:

I'm on linux mint 21. I used emacs with apheleia mode. But I just tested it from the console and had the same result.

— Reply to this email directly, view it on GitHub https://github.com/cmhughes/latexindent.pl/issues/411#issuecomment-1399256882, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7CYA37SWMUNZYSVPMYN3WTPTXNANCNFSM6AAAAAAT7V2XQ4 . You are receiving this because you commented.Message ID: @.***>

cmhughes commented 1 year ago

Here's a minimum script to try

#!/usr/bin/perl

use strict;                         #     |
use warnings;                       #     |
use Encode;                         #     |
use Getopt::Long;                   #     |
use Data::Dumper;                   #  these modules are
use List::Util qw(max);             #  generally part
use PerlIO::encoding;               #  of a default perl distribution
use open ':std', ':encoding(UTF-8)';#     |
use Text::Wrap;                     #     |
use Text::Tabs;                     #     |
use FindBin;                        #     |
use File::Copy;                     #     |
use File::Basename;                 #     |
use File::HomeDir;                  # <--- typically requires install via cpanm
use YAML::Tiny;                     # <--- typically requires install via cpanm

print "chapter{Introducción" ;
exit;
raziel408 commented 1 year ago

The output of that script is: chapter{Introducción its very likely your right and it has to do with my system. Thanks a lot for the help. I let you know if I find a solution.

cmhughes commented 1 year ago

I wonder if this is a font issue.... Do you have a way of checking the font on your operating system?

raziel408 commented 1 year ago

I think is not possible to be a font problem. My terminal is able to print uft-8 characters. I've been doing some testing. I was able to run the script in a new file. And it produced the right output to the terminal:

cat test.tex # produces the rigth output
latexindent test.tex # produces the rigth output

But after that pdflatex test.tex Produced a pdf with ó printed as ó My text editor also shows wrong encoding of the ó character. I also tested the minimal script in other systems and the output is: chapter{Introducción

cmhughes commented 1 year ago

I'm not sure what to do about this?

On Sun, 22 Jan 2023, 16:18 raziel408, @.***> wrote:

I think is not possible to be a font problem. My terminal is able to print uft-8 characters. I've been doing some testing. I was able to run the script in a new file. And it produced the right output to the terminal:

cat test.tex # produces the rigth output

latexindent test.tex # produces the rigth output

But after that pdflatex test.tex Produced a pdf with ó printed as ó My text editor also shows wrong encoding of the ó character. I also tested the minimal script in other systems and the output is: chapter{Introducción

— Reply to this email directly, view it on GitHub https://github.com/cmhughes/latexindent.pl/issues/411#issuecomment-1399534442, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7CYBW62OWGNTUMBMXJSDWTVMVZANCNFSM6AAAAAAT7V2XQ4 . You are receiving this because you commented.Message ID: @.***>

cmhughes commented 1 year ago

So do we think this is a problem with latexindent?

raziel408 commented 1 year ago

I'm not sure. I'm not experienced in perl. I tried to look a little more into that and found this question: https://stackoverflow.com/questions/627661/how-can-i-output-utf-8-from-perl But, I haven't had the time to look more into it. Sorry.

raziel408 commented 1 year ago

Hi, I managed to make the minimal example to work on my machine. I added the line: use utf8; I took it from the following question: https://stackoverflow.com/a/14658425 Hope that helps.

cmhughes commented 1 year ago

So perhaps the routine in Latexindent/Document.pm needs updating

sub output_indented_text

On Thu, 26 Jan 2023, 20:52 raziel408, @.***> wrote:

Hi, I managed to make the minimal example to work on my machine. I added the line use utf8; I took it from the following question: https://stackoverflow.com/a/14658425 Hope that helps.

— Reply to this email directly, view it on GitHub https://github.com/cmhughes/latexindent.pl/issues/411#issuecomment-1405634866, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7CYEBEJJ7GRJDVEGJYE3WULPYFANCNFSM6AAAAAAT7V2XQ4 . You are receiving this because you modified the open/close state.Message ID: @.***>

cmhughes commented 1 year ago

Do feel encouraged to take a look and submit a pull request if appropriate.

On Fri, 27 Jan 2023, 11:23 Chris Hughes, < @.***> wrote:

So perhaps the routine in Latexindent/Document.pm needs updating

sub output_indented_text

On Thu, 26 Jan 2023, 20:52 raziel408, @.***> wrote:

Hi, I managed to make the minimal example to work on my machine. I added the line use utf8; I took it from the following question: https://stackoverflow.com/a/14658425 Hope that helps.

— Reply to this email directly, view it on GitHub https://github.com/cmhughes/latexindent.pl/issues/411#issuecomment-1405634866, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7CYEBEJJ7GRJDVEGJYE3WULPYFANCNFSM6AAAAAAT7V2XQ4 . You are receiving this because you modified the open/close state.Message ID: @.***>

raziel408 commented 1 year ago

ok, thanks a lot.

cmhughes commented 1 year ago

For reference, it'll be

https://github.com/cmhughes/latexindent.pl/blob/f69cbfff6b1d22f1a729c2830d5f91537756135f/LatexIndent/Document.pm#L222

and I think you'll want the top answer from the link you shared https://stackoverflow.com/a/627672/1091649