Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the ltex-dictionary variable #5

Open
linwaytin opened this issue Aug 7, 2021 · 8 comments
Open

How to use the ltex-dictionary variable #5

linwaytin opened this issue Aug 7, 2021 · 8 comments

Comments

@linwaytin
Copy link

I would like to set up a list of technical words for the dictionary used by ltex.
I've tried

(setq lsp-ltex-dictionary "{\"en-US\": [\":~/myConfig/my-words.txt\"]}")

and

(setq lsp-ltex-dictionary "{\"en-US\": [\"quasiparticle\"]}")

but none of them works.
Does anyone know how to set up such a list? Thanks.

@HumHongeKamyaab
Copy link

same question, anyone managed to solve this?

@jcs090218
Copy link
Member

Sorry for the late reply! (Quite busy)

I have only set up these variables but haven't look into the usage. I will response to this thread after I have time to figure this out! 😓

@michaelmhoffman
Copy link

You need to set the variables in a form that json-serialize understands. From the Emacs documentation of json-serialize:

OBJECT must be a vector, hashtable, alist, or plist and its elements
can recursively contain the Lisp equivalents to the JSON null and
false values, t, numbers, strings, or other vectors hashtables, alists
or plists. t will be converted to the JSON true value. Vectors will
be converted to JSON arrays, whereas hashtables, alists and plists are
converted to JSON objects. Hashtable keys must be strings without
embedded NUL characters and must be unique within each object. Alist
and plist keys must be symbols; if a key is duplicate, the first
instance is used.

That means that in M-x customize-group lsp-ltex you can set lsp-ltex-dictionary to a hash-table with the values as vectors like this:

#s(hash-table size 30 data ("en-US" ["quasiparticle"]))

You can test this with (json-serialize lsp-ltex-dictionary) -> "{\"en-US\":[\"quasiparticle\"]}"

@linwaytin
Copy link
Author

linwaytin commented Dec 20, 2021

Thanks for your reply.
Does that mean I can do

(setq lsp-ltex-dictionary #s(hash-table size 30 data ("en-US" ["quasiparticle"])))

in my init file?

Also, can I set the variable from words in a separate file?
I think it is more reasonable to put the words in another file instead of the init file itself.
Thank you!

@michaelmhoffman
Copy link

Yes, you should be able to use the command you suggested.

I don't know how to make external files work here. Looking at the LTeX Language Server documentation and issues, it seems like external file support might be a feature of the client (LTeX for VS Code, or here lsp-ltex) rather than the server (LTeX LS). Not totally sure, though.

All I know is I haven't been able to external files to work and am probably going to stop using lsp-ltex for now. Having to restart every time I add a new word to the dictionary is too much. I do appreciate the effort of the author for providing this package for us.

@linwaytin
Copy link
Author

Thanks. Could you please explain what (hash-table size 30 ...) means? Does that mean only 30 words are allowed?

I found spell and grammar checking are not a simple issue, according to recent discussions on Reddit.

@rdiaz02
Copy link
Contributor

rdiaz02 commented Dec 31, 2021

I am facing the same issue and as @michaelmhoffman I find it having to restart whenever I add a word too much. So an alternative is to do spellchecking with, say, ispell/flyspell (so you can update dictionaries, etc), and keep grammar checking just for grammar checking, with spellchecking disabled.

This should be doable with lsp-ltex but I guess I am doing something wrong setting ltex.disabledRules via lsp-ltex-disabled-rules. As suggested by https://www.reddit.com/r/emacs/comments/ril2m4/grammar_checker_for_scientific_writing/hqqbxbm/ , we can tell lsp-ltex not to check spelling, at least in English. For example, (setq lsp-ltex-language "en") (i.e., use "en" instead of "en-US", as explained in https://valentjn.github.io/ltex/settings.html#ltexlanguage).

That does not always work, for example with Spanish (valentjn/ltex-ls#136) or if using Babel in a document (see https://valentjn.github.io/ltex/advanced-usage.html#multilingual-latex-documents-with-the-babel-package) but the following will disable spell checking for US English and Spanish:

(setq lsp-ltex-disabled-rules 
              #s(hash-table size 30 data 
                        ("en-US" ["MORFOLOGIK_RULE_EN_US"]
			  "es" ["MORFOLOGIK_RULE_ES"])
			))

Additional options to use only grammar checking: from this same set of tools, with flycheck-languagetool , https://github.com/emacs-languagetool/flycheck-languagetool ,"LanguageTool’s spellchecking will be disabled if flyspell-mode is active. " Alternatively, you can use textidote , https://github.com/sylvainhalle/textidote , but disable spellchecking. This is what I have in my textidote flycheck checker "--ignore" "lt:en:MORFOLOGIK_RULE_EN_US,lt:es:MORFOLOGIK_RULE_ES" (see https://github.com/sylvainhalle/textidote#emacs-integration for how to use textidote from emacs).

@abougouffa
Copy link
Member

I'm using this syntax for the similar lsp-ltex-disabled-rules variable:

(setq lsp-ltex-disabled-rules
      '(:fr ["WHITESPACE" "FRENCH_WHITESPACE" "DEUX_POINTS_ESPACE"]
        :en ["WHITESPACE"]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants