Difference between revisions of "User talk:Koenich"

From Wiki
Jump to navigation Jump to search
Line 256: Line 256:
 
* The included files are a migration of ConTeXt settings for SciTE. They might work not as expected.
 
* The included files are a migration of ConTeXt settings for SciTE. They might work not as expected.
 
* The included <code>init.lua</code> is not empty. If you edited yours already, your changes will be overwritten. You can circumvent this by renaming ConTeXt's <code>init.lua</code> to something different like <code>dinit.lua</code> and load the renamed file directly from your own <code>init.lua</code> by using the following code:
 
* The included <code>init.lua</code> is not empty. If you edited yours already, your changes will be overwritten. You can circumvent this by renaming ConTeXt's <code>init.lua</code> to something different like <code>dinit.lua</code> and load the renamed file directly from your own <code>init.lua</code> by using the following code:
   require('dinit.lua')
+
   require('dinit.lua') -- Exemplary file name!
 
* The files are numberous and come within a strict structure that must not be changed. It might be difficult for users to understand the code and change settings. It might be more worthwile to create an own lexer for context. A good starting point for this is the context-lexer that comes with TA. It's located in the folder <code>Textadept\lexers</code>. Further help can be found in the [https://foicica.com/textadept/api.html#lexer lexer section] of Textadept's [https://foicica.com/textadept/api.html API manual].
 
* The files are numberous and come within a strict structure that must not be changed. It might be difficult for users to understand the code and change settings. It might be more worthwile to create an own lexer for context. A good starting point for this is the context-lexer that comes with TA. It's located in the folder <code>Textadept\lexers</code>. Further help can be found in the [https://foicica.com/textadept/api.html#lexer lexer section] of Textadept's [https://foicica.com/textadept/api.html API manual].
  

Revision as of 13:16, 9 August 2018

UPDATES

2018/08/09:

-> slight changes due to version change of Textadept (v9.6 -> v10.0), especially for changing themes

-> corrected some minor mistakes

-> in the future I will leave only the last three changelogs (updates) on this page

2018/07/13:

-> added a *preamble*

-> changed structure a little, for more fluid reading and navigation

-> minor updates to the main text

-> some TeX and LaTeX trivia and/or comparisons will be added in the future

Preamble

Here is the place to get everything that is important to get started with ConTeXt (mkiv) and Textadept on MS Windows systems.

Note that this page is a User talk, which might differ from usual wiki-entries. In the end this page is meant to be of personal purpose. This means that there is no absolute truth to be found within this page. Experience might differ heavily from the expected results. Here I, Koenich, will try to add as much info as I could gather on my way of learning, what I like to abbreviate CTX, ConTeXt.

Hopefully the readers (of which there seem to be a lot; from 0 to over 9000 views within 1.5 years [minus a dozen of my own previews :D]) will get a better understanding of what ConTeXt is, what its advantages and disadvantages are, also compared to other popular software, and how Textadept can be used to get the most out of ConTeXt regarding an efficient work-flow.

(Thanks to especially *Donald Knuth*, *Hans Hagen* and too many other coders and users to mention right here!)

Introduction

ConTeXt is a TeX macro package created and maintained by Pragma ADE. The recent version mkiv is widely extensible using Lua.

Textadept is a programmable text editor for Linux, Mac OSX and Windows, created and maintained by Mitchell. It is fully extensible using Lua.

I: Quick setup

I.C: Quick setup ConTeXt

I.C Step 1: Install / Update ConTeXt

Installation and update of ConTeXt work the same way. If you only want to update ConTeXt, you can go to point 3.

1. Download ConTeXt.

2. Extract the archive to a location of your choice.

  • You might want to change the name of the extracted directory to a shorter one as it will be the final location for ConTeXt.

3. Install / Update ConTeXt

3. Method 1: Write a batch file

Since at this point the installation and update of ConTeXt work the same way, the most effective solution is to create a batch file. To do so

  • use Windows Explorer to navigate to your ConTeXt directory. In there should be a file called first-setup.bat.
  • Use Windows Notepad or Right-click -> New -> Textfile to create such.
  • If you only want ConTeXt mkiv (highly recommended), add the following line to the new and empty textfile:
 first-setup -engine=luatex -modules=all
  • Save the file as a batch-file and name it something like update.bat.
    • Note that the document ending has to be .bat not .txt or anything else. You might have to rename the file ending by hand.
  • Execute the batch file you just created by double-clicking on it. A command prompt window should pop up.
    • If it appears for only a few seconds, chances are high that the download server is down. In that case you might want to re-try the procedure at some other time.
  • Wait for the download / update to finish. After it is done, the command window should disappear by itself.
    • ConTeXt's folder's size should be around 380 - 400 MB when everything worked fine.

From here you can go to I.C Step 2 directly.

3. Method 2: Type the command by hand

  • Use Windows Explorer to navigate to your ConTeXt directory.
    • Click into the upper white field where the current location is displayed.
    • Enter cmd and press Enter-key.
    • Now Windows command prompt should pop up with the correct location.
  • Otherwise you can start your Windows command prompt
    • by using the key shortcut Windows-key + R, entering cmd and pressing Enter-key.
    • Alternatively you can use Start -> Programs -> Accessories -> Command Pompt.
  • Some important MS DOS commands:
    • dir list the content of the current directory
    • cd DIRECTORY change to directory with name DIRECTORY
    • cd.. change to superior directory
    • cd\ change to drive root
    • X: change to drive X:
    • also possible: cd directory\subdirectory\subsubdir...
  • In the end your command prompt should look like this:
 X:\ConTeXt>_
  • If you only want ConTeXt mkiv (highly recommended), enter the following line and press Enter-key:
 first-setup -engine=luatex -modules=all -fonts=all
  • Wait until the download / update is complete. Afterwards you can close the command prompt by entering exit and pressing Enter-key or by simply closing the window.

I.C Step 2: Add ConTeXt's executables folder to Windows search Path

Note: you will need admin rights for this. On public machines for example you most probably won't be able to add ConTeXt to that machine's path.

1. Open Windows' System dialog

  • either by Right-clicking on This PC / My Computer on your Desktop and then clicking on Properties
  • or by clicking Start -> Settings -> About -> System Info
  • or on older Windows Machines by going to Control Panel -> System.

2. Click on Advanced System Settings ("System Properties").

3. Click on Advanced-Tab.

4. Click on Environment Variables....

5. Choose where to add ConTeXt's executables folder to:

  • Either to User variables for USER for the current user only
  • or to System variables for all users.

6. Double-click on the respective variable called Path.

7. Add your ConTeXt executables to Windows path.

  • Note that the position, to where you add the location is sorted by importancy. The most important directories will be searched first. This might be taken into account when using ConTeXt together with MiKTeX for example. It's safest to place ConTeXt's path at the very beginning.
  • In User Path variable you might need to add the location and seperate it from the existing ones by using a semikolon (;).
  • In System Path variable you probably only have to add a new line.

The location should look like this:

  • Win x86 / 32 bit:
 X:\ConTeXt\tex\texmf-mswin\bin
  • Win x64 / 64 bit:
 X:\ConTeXt\tex\texmf-win64\bin

8. Save your changes. Usually no restart or re-login is needed after this operation.

Opt 1. You can test whether it worked by starting your Command prompt and entering the following line, while being in a directory other than the one you just added.

 context -version
  • A message with ConTeXt's version number should apear.
  • If a message like 'context' is not recognized as an internal or external command... appears, you should make sure that you added the correct location of ConTeXt's executables (context.exe) path to Windows' search path or re-try the operation by starting from Step 2.1.

I.T: Quick setup Textadept

I.T Step 1: Install Textadept

1. Download and extract Textadept to a folder of your choice.

2. Use textadept.exe from the extracted folder to start Textadept.

I.T Step 2: Tweak Textadept's settings

Note that almost all changes to Textadept are saved in the file init.lua. There is two of them, of which you should edit only one:

  • One of them is in the extracted Textadept main folder. It is not recommended to edit this file as your changes will be lost when you update Textadept. Instead:
  • When you start Textadept for the first time, a new folder SYSDRIVE:\users\USERNAME\.textadept gets created. It also contains a file called init.lua. This is the file and location where you should save all your Textadept settings. This way you can make a copy and use it on several computers. When you open it for the first time it should be empty.

Usually you have to restart Textadept after changing its configuration files. Robert Gieseke created a code though, which you can add to your init.lua to circumvent having to restart Textadept whenever a change is made:

 -- Save and reset Lua state: F9
 keys['f9'] = function()    -- Mac OSX users might prefer:    keys[OSX and 'mf9' or 'f9']
   io.save_file()
   reset()
 end

Save init.lua and restart Textadept once. After doing so you can add changes to Textadept's configuration files and press F9-key afterwards to save and load the changes without having to restart Textadept.

I.T Step 2.1: Bind a PDF build command into Textadept

2.1.1. Use Textadept to open your init.lua stored in SYSDRIVE:\users\USER\.textadept\.

2.1.2. Add an execute command for ConTeXt to Textadept's menu:

 textadept.run.compile_commands.tex = 'mtxrun --autogenerate --script context --autopdf --purge --synctex=-1 "%f"'
  • Note that your ConTeXt executables folder has to be in the Windows search path!

2.1.3. Restart Textadept to reload the modified init.lua.

2.1.4. Open or create a ConTeXt test document:

 \starttext
   hello world!
 \stoptext
  • You will have to save the file with an appropriate ending first, after that it will be recognized as ConTeXt format file automatically.

2.1.5. Use Textadept's Tools -> Compile to build a PDF with the options added to init.lua. A message buffer with compilation status will open in a seperate tab.

2.1.6. When you have a popular PDF reader installed already, it should pop up at the end of the process and show the created PDF output. Sumatra PDF is highly recommended for this.

I.T Step 2.2: Lexing (command highlighting & code folding)

A lexer is a file that defines command highlighting and code folding keywords. Textadept comes with a ConTeXt lexer. In order to be able to use command highlighting and code folding when writing ConTeXt documents, you have to bind those documents to the lexer. To do so

2.2.1. add the following line to your USER/.textadept/init.lua and save it afterwards:

 textadept.file_types.extensions.tex = 'context'
  • If you plan to use LaTeX and ConTeXt, you might want to use different file extensions for each format. For example *.tex for LaTeX and *.cxd for ConTeXt documents. In that case you only have to bind your new ConTeXt extension to Textadept's ConTeXt lexer, since .tex files are automatically recognized as LaTeX documents:
 textadept.file_types.extensions.cxd = 'context'
  • When linking files within ConTeXt documents without adding an extension though, ConTeXt will expect those files to have the ending *.tex, i.e. you will have to work with filenames and extensions when using a format other than *.tex, which on the other hand should not be seen as a disadvantage.

2.2.2. Restart Textadept to reload init.lua.

2.2.3. Open a ConTeXt document and check Textadept's status bar in the lower right corner. It should say context. If it says latex make sure it really is a ConTeXt file or repeat the procedure.

Optional: Additional Textadept tweaks

Themes & editor font changes

You can change the theme, font and font size of Textadept with the following line

 buffer:set_theme('light', {font = 'Monospace', fontsize = 10})

in which the expression light is the filename of the theme located in either Textadept\themes or USER\.textadept\themes (after you created the folder and downloadeded and added theme files to it).

  • There are more settings which you can look up in Textadept's manual.

Snippets

Snippets are predefined code or text blocks. Using snippets can save a lot of time as you won't have to retype often used commands and text passages. You add snippets to your USER/.textadept/init.lua. Alternatively you can create a new file, e.g. USER/.textadept/mysnippets.lua, add all snippets to that file and load it from within your init.lua with the following line:

 require('mysnippets')

In Textadept snippets look like this:

 snippets.context['TRIGGERKEYWORD'] = 'PASTEDTEXT'

To get an idea how writing snippets (for ConTeXt) works, you can copy and paste the following list to your init.lua:

 -- The first line is mandatory:
 snippets['context'] = snippets['context'] or {}
 -- Snippets start here:
 snippets.context['emph']        = '{\\em %<selected_text>%0}' -- emphasized text/math
 snippets.context['ital']        = '{\\it %<selected_text>%0}' -- italic text/math
 snippets.context['bold']        = '{\\bf %<selected_text>%0}' -- bold text/math
 snippets.context['boldit']      = '{\\bi %<selected_text>%0}' -- bold italic text/math
 snippets.context['start']       = '\\start%1\n\t%0\n\\stop%1'
 snippets.context['itemize']     = '\\startitemize[packed]\n\t\\startitem\n\t\t%<selected_text>%0\n\t\\stopitem\n\\stopitemize' -- start itemization
 snippets.context['item'] 	 = '\\startitem\n\t%<selected_text>%0\n\\stopitem'
 snippets.context['enumerate']   = '\\startenumerate\n\t%0\n\\stopenumerate'
 snippets.context['chapter']     = '\\startchapter[title={%1},marking{%2}]\n\t%0\n\\stopchapter'
 snippets.context['section']     = '\\startsection[title={%1},marking{%2}]\n\t%0\n\\stopsection'
 snippets.context['ssection']    = '\\startsubsection[title={%1},marking{%2}]\n\t%0\n\\stopsubsection'
 snippets.context['title']       = '\\starttitle[title={%1},marking{%2}]\n\t%0\n\\stoptitle'
 snippets.context['subject']     = '\\startsubject[title={%1},marking{%2}]\n\t%0\n\\stopsubject'
 snippets.context['ssubject']    = '\\startsubsubject[title={%1},marking{%2}]\n\t%0\n\\stopsubsubject'
  • Note that a backslash \ is set by typing a double backslash \\.
  • The most important formatting commands are the following:
    • \n set a line break (new line)
    • \t set a tabulated
    • %0 set the closing caret (placeholder) (the cursor will jump here last)
    • %1 set one or multiple input carets (%1, %2, %3 and so on; you can also use the same integer multiple times: e.g. \\start%1 ... \\stop%1)
    • %<selected_text> this is where highlighted text will be pasted when enclosing it with a snippet (e.g. {\\bi %<selected_text>%0})
  • After adding snippets, you have to restart Textadept or reset Lua state as described in Step 2.
  • You can paste snippets into ConTeXt documents
    • either by typing the keyword that you defined within snippets.context['KEYWORD'] and pressing Tab-key afterwards
    • or by using Ctrl + K (by default on Windows machines) to choose from the list of snippets. No matter in which order you add them to your init.lua, they will show up sorted alphabetically.
  • Note that since this way you bound snippets to Textadept's ConTeXt lexer, Textadept's status bar in the lower right corner has to say context, otherwise use a ConTeXt document or see Step 2.2.
  • Learn more about snippets in Textadept's manual.

ConTeXt's Textadept settings

ConTeXt comes with configuration files (a lexer and a theme) for Textadept that can be found in \ConTeXt\tex\texmf-context\context\data\textadept\context. They can basically be copied from context folder to your USERNAME\.textadept folder. They might be the best choice for unexperienced users, yet there are some things to be taken into account before usage:

  • The included files are for Textadept 9 only. Using the files unchanged with Textadept 10 will give errors and make TA unusable (until you update or delete them).
  • The included files are a migration of ConTeXt settings for SciTE. They might work not as expected.
  • The included init.lua is not empty. If you edited yours already, your changes will be overwritten. You can circumvent this by renaming ConTeXt's init.lua to something different like dinit.lua and load the renamed file directly from your own init.lua by using the following code:
 require('dinit.lua') -- Exemplary file name!
  • The files are numberous and come within a strict structure that must not be changed. It might be difficult for users to understand the code and change settings. It might be more worthwile to create an own lexer for context. A good starting point for this is the context-lexer that comes with TA. It's located in the folder Textadept\lexers. Further help can be found in the lexer section of Textadept's API manual.

3rd party projects

A ConTeXt module for Textadept is being developed at ta-context-latex.

Note though, that if you plan to use Textadept without LaTeX with ConTeXt mkiv only (recommended), then you might not need the package mentioned above as it comes with literally only a hand full of ConTeXt snippets. It also needs additional software to be installed (Textredux, ctags), so that it's almost more comfortable to create own ConTeXt snippets with the ease of Textadept (see above).