ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Redefine symbols for new command \morse{.-..}
@ 2010-12-10 10:17 Jonas Stein
  2010-12-10 12:09 ` Hans Hagen
  0 siblings, 1 reply; 2+ messages in thread
From: Jonas Stein @ 2010-12-10 10:17 UTC (permalink / raw)
  To: ntg-context

i'd like to define a new command

\define[]\short{\dontleavehmode \blackrule[width=0.4em]\ }
\define[]\long {\dontleavehmode \blackrule[width=1.4em]\ }
\define[1] \morse {MAGIC}

\morse{.-..} 
should create a \short for every '.' and \long for every '-'
But this transcription should be only active in the 
"morse environment"

Is that possible? Who knows the MAGIC?

Kind regards,

-- 
Jonas Stein <news@jonasstein.de>

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Redefine symbols for new command \morse{.-..}
  2010-12-10 10:17 Redefine symbols for new command \morse{.-..} Jonas Stein
@ 2010-12-10 12:09 ` Hans Hagen
  0 siblings, 0 replies; 2+ messages in thread
From: Hans Hagen @ 2010-12-10 12:09 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: text/plain, Size: 687 bytes --]

On 10-12-2010 11:17, Jonas Stein wrote:
> \define[]\short{\dontleavehmode \blackrule[width=0.4em]\ }
> \define[]\long {\dontleavehmode \blackrule[width=1.4em]\ }
> \define[1] \morse {MAGIC}
>
> \morse{.-..}

up to you to complete the tables ... after that I'll clean up the code a 
bit


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: m-morse.mkiv --]
[-- Type: text/x-matlab; name="m-morse.mkiv", Size: 2751 bytes --]

\startluacode
moduledata.morse = moduledata.morse or { }

local morsecodes = {
    ["A"] = "·—",
    ["B"] = "—···",
    ["C"] = "—·—·",
    ["D"] = "—··",
    ["E"] = "·",
    ["F"] = "··—·",
    ["G"] = "——·",
    ["H"] = "····",
    ["I"] = "··",
    ["J"] = "·———",
    ["K"] = "—·—",
    ["L"] = "·—··",
    ["M"] = "——",
    ["N"] = "—·",
    ["O"] = "———",
    ["P"] = "·——·",
    ["Q"] = "——·—",
    ["R"] = "·—·",
    ["S"] = "···",
    ["T"] = "—",
    ["U"] = "··—",
    ["V"] = "···—",
    ["W"] = "·——",
    ["X"] = "—··—",
    ["Y"] = "—·——",
    ["Z"] = "——··",
    ["0"] = "—————",
    ["1"] = "·————",
    ["2"] = "··———",
    ["3"] = "···——",
    ["4"] = "····—",
    ["5"] = "·····",
    ["6"] = "—····",
    ["7"] = "——···",
    ["8"] = "———··",
    ["9"] = "————·",
    ["."] = "·—·—·—",
    [","] = "——··——",
    ["?"] = "··——··",
    ["-"] = "—····—",
    ["/"] = "—··—· ",
    [":"] = "———···",
    ["'"] = "·————·",
    ["-"] = "—····—",
    [")"] = "—·——·—",
    [";"] = "—·—·— ",
    ["("] = "—·——·",
    ["="] = "—···—",
    ["@"] = "·——·—·",
}

local simplecodes = {
    ["."] = "·",
    ["-"] = "—",
}

function moduledata.morse.tomorse(str,translate)
    if translate then
        str = utf.gsub(string.upper(str),".",morsecodes)
    else
        str = utf.gsub(str,".",simplecodes)
    end
    context.ignorespaces()
    for s in string.utfcharacters(str) do
        if s == "·" then
            context.MorseShort()
        elseif s == "—" then
            context.MorseLong()
        elseif s == "\n" or s == " " then
            context.MorseSpace()
        else
            context.MorseUnknown(s)
        end
    end
    context.removeunwantedspaces()
end

function moduledata.morse.filetomorse(name,translate)
    moduledata.morse.tomorse(resolvers.loadtexfile(name),translate)
end

\stopluacode

\unprotect

\def\MorseShort    {\dontleavehmode\blackrule[\c!width=0.4em]\space}
\def\MorseLong     {\dontleavehmode\blackrule[\c!width=1.4em]\space}
\def\MorseSpace    {\emspace}
\def\MorseUnknown#1{\emspace}
\def\MorseCode   #1{\ctxlua{moduledata.morse.tomorse("#1")}}
\def\Morse       #1{\ctxlua{moduledata.morse.tomorse("#1",true)}}
\def\MorseFile   #1{\ctxlua{moduledata.morse.filetomorse("#1",true)}}

\unprotect

\starttext

\MorseCode{.-..}

\Morse{CONTEXT}

\MorseFile{tufte}

\stoptext

[-- Attachment #3: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-12-10 12:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-10 10:17 Redefine symbols for new command \morse{.-..} Jonas Stein
2010-12-10 12:09 ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).