I'm using the permalink_fu plugin to create permalinks from titles. My problem is: If the title contains german characters, they are just replaced with '_'.
What I need is something that replaces
ä with ae
ü with ue
ö with oe
I fount String.tr but the problem here is that it replaces 1 character with 1 replacement, so it would work for replacing
é with e
ø with o
etc.
Does anyone have a nice and clean solution for that?
Thanks
Look at transliterate and parameterize (with transliterations in locales/de.yml):
http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-transliterate
I18n.transliterate("Über der Höhenstraße")
=> "Ueber der Hoehenstrasse"
http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-parameterize
"Über der Höhenstraße".parameterize
=> "ueber-der-hoehenstrasse"
If you don't want to write the transliterations yourself, you can install the rails-i18n gem.
I have written a small Library called Asciify for exactly that purpose
$ sudo gem install asciify
Usage:
#!/bin/ruby
require "asciify"
"Lücke".asciify #=> "Luecke"
You can provide a YAML-file for custom mappings like so:
translator = Asciify.new("/path/to/mappings.yaml")
output_string = translator.convert("input string")
(see the builtin default mapping for the expected format)
The whole project is quite old, but maybe it does the job you need it to. If not, maybe the source code will be helpful.
Use String.gsub():
"ich bin doch nicht blöd, mann!".gsub(/[äöü]/) do |match|
case match
when "ä"
'ae'
when "ö"
'oe'
when "ü"
'ue'
end
end
Of course, the lookup can be improved by using a lookup table, but the principle should be clear.
"äöü".gsub('ä','ae').gsub('ö','oe').gsub('ü','ue')
;)
Try String.sub!.
I asked a similar question once. It was for JavaScript, and it takes a regex based aproach. Maybe the solution still carries some value for you, methodologically speaking.
Try using this: "Ich bin doch nicht böld ähhh ühh öhhh".gsub(/[äöüßÄÖÜ„“§%&–+]/){|t|t.to_xs}
Related
Going over source code written in Ruby, like Rails, I often see that small code is wrapped with tt tag, like in rails/activesupport/core_ext/array/access.rb
# Equal to <tt>self[2]</tt>.
#
# %w( a b c d e).third # => "c"
def third
self[2]
end
What is the convention behind this, when and why it was decided to use this notation?
Yep, my mistake, sorry
This is a part of special RDoc system.
Non-verbatim text can be marked up:
italic: word or <em>text</em>
bold: word or <b>text</b>
typewriter: word or <tt>text</tt>
Read more about it here
Found it by myself in the Rails documentation guide.
Using a pair of +...+ for fixed-width font only works with words; that
is: anything matching \A\w+\z. For anything else use <tt>...</tt>,
notably symbols, setters, inline snippets, etc:
I would like to globally prevent LaTeX from hyphenating 'Objective-C'. I am aware of the \hyphenation command, but I don't see how I can make use of it. If I pass 'Objective-C' to this command, the dash will be treated as a hint to hyphenate the word there.
One solution I found is wrapping Objective-C into an mbox each time I use it. However, the document I am writing contains this name a lot, and wrapping it into an mbox each time is ugly (as is defining a command and using this over and over again in the source code).
Why is defining a new command ugly? It's how \LaTeX\ defines itself.
\def\ObjectiveC{\mbox{Objective-C}}
Use \nobreakdash. That's what LyX produces when I insert a nonbreakingdash and convert it to tex.
As suggested here, you could define a command like this:
\newcommand\dash{\nobreakdash-\hspace{0pt}}
and use it like this
Consider the $n$\dash dimensional manifold ...
Also, you could use the babel package and use "~ as a protected hyphen. I'm not sure if using babel is advisable when writing in english, though.
Despite the fact that XML attributs can be defined using single or double quotes, my user is trying to integrate my software with another one that will not accept single quoted attribut values.
I user REXML to generate my XMLs.
Is there a way to REXML generate double quoted attribute values?
If not, is there a way for me to convert it easily?
Thanks
As of Feb 2007 there's a supported way of determining the quoting character. The changes were merged into Ruby sources on Jul 2007 and should be available on all versions since 1.8.6-p110:
require 'rexml/document'
doc = REXML::Document.new
doc.context[:attribute_quote] = :quote # <-- Set double-quote as the attribute value delimiter
root = doc.add_element('root')
root.add_attribute('val', '123')
doc.write(STDOUT)
Running that yields:
$ ruby test.rb
<root val="123"/>
$
I've seen this code around to do this. But it's from a 2003 mailing list post that also promises a more elegant (and supported) way of doing it. Might not be the best, but it could work, give it a try.
REXML::Attribute.class_eval( %q^
def to_string
%Q[##expanded_name="#{to_s().gsub(/"/, '"')}"]
end
^ )
I am trying to write my CV, and I want to include a list of publications. To do that, I want to include a .bbl file directly (which was generated using bibtex).
So, in my CV I do
\input{publications.bbl}
This seems to work fine, except for one thing: an asterisk (*) appears on the left to the lists of publications! I don't know where this * comes from and why it appears there. Any idea how I can remove this *?
Thanks.
The thebibliography environment is already included in .bbl files so processing the file with
\input{publications.bbl} should be enough.
The format of the publication list depends on the bibliography style used by BibTex with
the \bibliographystyle command. For more information about available styles take a look at:
https://en.wikibooks.org/wiki/LaTeX/Bibliography_Management#Bibliography_styles
Did you use \nocite{*}? putting \nocite{*} before \bibliographystyle can cause the asterisk to appear.
I had the same issue, this works for me:
\bibliographystyle{IEEEtran}
\nocite{*}
\bibliography{my_bib_file}
I'd have to see some code. but first you do
\begin{thebibliography}{}
\input{publications.bbl}
\end{thebibliography}
Is that what you have? In fact, try this and see if you still get the "error":
\begin{thebibliography}{}
\bibitem{ano05}
A. Nonymous et al.\ 2005, \aap 123, 456\\[-20pt]
\bibitem{oe04}
A.N. Other \& S.O.M. Ebody 2004, \pasp 123, 456\\[-20pt]
\end{thebibliography}
In my english thesis latex file, how to mention the following non English words: François, École Fédérale?
Thanks and regards!
The traditional way is to use the accent-adding macros:
Fran\c{c}ois
\'Ecole F\'ed\'erale
(You can also write Fran\c{}cois or Fran\c cois; the \c macro uses no parameter; the braces or space are just a trick to allow LaTeX to see the proper macro name.)
Otherwise, try this:
\usepackage[utf8]{inputenc}
and type the accents directly, with UTF-8 encoding.
There are a host of more-or-less subtle issues with fonts and hyphenation.
If you don't go the UTF8 inputenc route, and yet find yourself writing a lot of these names, I'd suggest defining macros for them. At the simplest, you can say \newcommand\Francois{Fran\c cois} but then you need to be sure to use it as such: \Francois{} so that any spaces afterwards don't get gobbled.
On the other hand, the following technique works pretty well too (though I can't take credit for inventing it - I saw it originally in a short talk at BachoTeX 2009 by Philip Taylor):
\makeatletter
\let\latex#less<
\catcode`<13
\def<{\ifmmode\latex#less\else\expandafter\find#name\fi}
\def\find#name#1>{\#nameuse{name.#1}}
\def\DefineName#1#2{\#namedef{name.#1}{#2}}
\makeatother
Now you can define special names using, e.g.
\DefineName{Francois}{Fran\c cois}
\DefineName{Ecole Federale}{\'Ecole F\'ed\'erale}
and later on you can use them in text with
I ran into <Francois> at the <Ecole Federale> the other day.
You can make your tags (the plain ASCII versions) be whatever you want - they don't have to actually be related to the properly accented names.
EDIT: in response to the issue that misspelled names don't produce errors, you can change the definition of \find#name to
\def\find#name#1>{\ifcsname name.#1\endcsname
\#nameuse{name.#1}%
\else
\#latex#warning{Undefined name #1}%
\fi}
Note that \#latex#warning{...} can be changed to \#latex#error{...}\#eha and it will complain more forcefully. Or if you want to pretend to be (or actually be) a package you can use \Package(Warning|Error){<package name>} in place of \#latex#(warning|error) and it won't pretend to be a built-in LaTeX error anymore.