Skip to content

Instantly share code, notes, and snippets.

@kmuto
Created March 4, 2019 14:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmuto/99748f999acb7bfa140ded5672f0c3ea to your computer and use it in GitHub Desktop.
Save kmuto/99748f999acb7bfa140ded5672f0c3ea to your computer and use it in GitHub Desktop.
tt, code内の'をtextquotesingleの形にする(textttを書き換えるのはいろいろ大変らしいので…)
module ReVIEW
module LATEXBuilderOverride
def inline_tt(s)
super(s).gsub("'", '\textquotesingle ').sub(/(textquotesingle) }$/, '\1}')
end
def inline_code(s)
super(s).gsub("'", '\textquotesingle ').sub(/(textquotesingle) }$/, '\1}')
end
end
class LATEXBuilder
prepend LATEXBuilderOverride
end
end
@mikesorae
Copy link

mikesorae commented Mar 4, 2019

ありがとうございます!

spaceが消えてしまうのと、backquoteも考慮して以下のようにしてみました。

module ReVIEW
  module LATEXBuilderOverride
    def inline_tt(s)
      super(s)
        .gsub(" ", '\ ')
        .gsub("'", '\textquotesingle ').sub(/(textquotesingle) (?!.*textquotesingle)$/, '\1')
        .gsub("`", '\textasciigrave ').sub(/(textasciigrave) (?!.*textasciigrave)$/, '\1')
    end

    def inline_code(s)
      super(s)
        .gsub(" ", '\ ')
        .gsub("'", '\textquotesingle ').sub(/(textquotesingle) (?!.*textquotesingle)$/, '\1')
        .gsub("`", '\textasciigrave ').sub(/(textasciigrave) (?!.*textasciigrave)$/, '\1')
    end
  end

  class LATEXBuilder
    prepend LATEXBuilderOverride
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment