Используйте sed для форматирования абзацев для latex

Чтобы сделать это специально для xterm, добавьте следующую строку к Вашему файлу ~/.Xresources:

xterm*termName: xterm-256color

Перезагрузите Ваш .Xresources с помощью:

xrdb ~/.Xresources

Или выйдите из системы, а затем снова войдите в систему.

Другой вариант - добавить к Вашему файлу следующее. bashrc (или эквивалентный файл, который будет исходить при запуске оболочки):

[ "$TERM" = xterm ] && export TERM=xterm-256color

Единственная опасность заключается в том, что многие другие клеммы, которые на самом деле не являются xterm, устанавливают TERM на xterm. Если вы используете такой терминал, который не поддерживает 256 цветов, у вас могут возникнуть проблемы.

.
1
29.10.2015, 20:00
2 ответа

Что-то вроде этого:

sed '/Hymn/,/Amen/{                                 # in this range
/Hymn/{                                             # if line matches Hymn
s/.*/\\small\{\\uppercase\{&\}\}\\normalsize/       # replace as required
h                                                   # copy over the hold space
s/.*/\\begin\{verse\}/                              # replace with \begin{verse}
H                                                   # append to hold space
d                                                   # delete the line
}
/Amen/!{                                            # if line doesn't match Amen 
/^$/!{                                              # and if line is not empty
s/$/\\\\/                                           # add trailing \\
}
H                                                   # append to hold space
d                                                   # then delete line
}
//{                                                 # if line matches Amen
s/$/\\\\!/                                          # add trailing \\!
H                                                   # append to hold space
s/.*/\\end\{verse\}/                                # replace with \end{verse}
H                                                   # append to hold space
s/.*//                                              # empty pattern space
x                                                   # exchange buffers
s/\n\n/!&/g                                         # add ! at end of each para
}
}
' infile

или, если вы предпочитаете gnu sed с двумя строками:

sed '/Hymn/,/Amen/{/Hymn/{s/.*/\\small\{\\uppercase\{\&\}\}\\normalsize/;h;s/.*/\\begin\{verse\}/;H;d}
/Amen/!{/^$/!{s/$/\\\\/};H;d};//{s/$/\\\\!/;H;s/.*/\\end\{verse\}/;H;s/.*//;x;s/\n\n/!&/g}}' infile

Выход с вашим образцом:

\small{\uppercase{Hymn I}}\normalsize
\begin{verse}
Conditor alme siderum,\\
Aeterna lux credentium,\\
Christe, redemptor omnium,\\
Exaudi preces supplicum.\\!

Qui condolens interitu\\
Mortis perire saeculum,\\
Salvasti mundum languidum,\\
Donans reis remedium.\\!

Vergente mundi vespere,\\
Uti sponsus de thalamo,\\
Egressus honestissima\\
Virginis matris clausula. Amen.\\!
\end{verse}

\small{\uppercase{Hymn II}}\normalsize
\begin{verse}
...\\
... Amen.\\!
\end{verse}
2
27.01.2020, 23:36

Я бы использовал perl в режиме абзаца.

#!/usr/bin/env perl
# Usage: thisprogram < inputfile > outputfile
use strict;
use warnings;
use feature qw(say);

$/ = "\n\n";    # paragraph mode

while (<>) {
  # nuke last \n of paragraph due to
  s/[\n]+\z//;
  # the need to replace the mid-verse newlines with \\
  s/\n/\\\\\n/g;
  # and now actually undo that while working on the first line
  s/(Hymn \w+)[\\]+/\\small{\\uppercase{$1}}\\normalsize\n\\begin{verse}/;
  # and at the newline-free end of the paragraph, tack on the \\! bit
  s/\z/\\\\!/;
  # emit
  say;
  if (m/Amen\./) {
    say "\\end{verse}\n";
  } else {
    print "\n";
  }
}
0
27.01.2020, 23:36

Теги

Похожие вопросы