HumanReadableLogsHints.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. import {
  2. packageSuggestionsForCommands,
  3. packageSuggestionsForEnvironments,
  4. } from './HumanReadableLogsPackageSuggestions'
  5. import getMeta from '@/utils/meta'
  6. function WikiLink({
  7. url,
  8. children,
  9. }: {
  10. url: string
  11. children: React.ReactNode
  12. }) {
  13. if (getMeta('ol-wikiEnabled')) {
  14. return (
  15. <a href={url} target="_blank" rel="noopener">
  16. {children}
  17. </a>
  18. )
  19. } else {
  20. return <>{children}</>
  21. }
  22. }
  23. type LogHint = {
  24. extraInfoURL?: string | null
  25. formattedContent: (details?: string[]) => React.ReactNode
  26. }
  27. const hints: { [ruleId: string]: LogHint } = {
  28. hint_misplaced_alignment_tab_character: {
  29. extraInfoURL:
  30. 'https://www.overleaf.com/learn/Errors/Misplaced_alignment_tab_character_%26',
  31. formattedContent: () => (
  32. <>
  33. You have placed an alignment tab character '&' in the wrong place. If
  34. you want to align something, you must write it inside an align
  35. environment such as \begin
  36. {'{align}'} … \end
  37. {'{align}'}, \begin
  38. {'{tabular}'} … \end
  39. {'{tabular}'}, etc. If you want to write an ampersand '&' in text, you
  40. must write \& instead.
  41. </>
  42. ),
  43. },
  44. hint_extra_alignment_tab_has_been_changed: {
  45. extraInfoURL:
  46. 'https://www.overleaf.com/learn/Errors/Extra_alignment_tab_has_been_changed_to_%5Ccr',
  47. formattedContent: () => (
  48. <>
  49. You have written too many alignment tabs in a table, causing one of them
  50. to be turned into a line break. Make sure you have specified the correct
  51. number of columns in your{' '}
  52. <WikiLink url="https://www.overleaf.com/learn/Tables">table</WikiLink>.
  53. </>
  54. ),
  55. },
  56. hint_display_math_should_end_with: {
  57. extraInfoURL:
  58. 'https://www.overleaf.com/learn/Errors/Display_math_should_end_with_$$',
  59. formattedContent: () => (
  60. <>
  61. You have forgotten a $ sign at the end of 'display math' mode. When
  62. writing in display math mode, you must always math write inside $$ … $$.
  63. Check that the number of $s match around each math expression.
  64. </>
  65. ),
  66. },
  67. hint_missing_inserted: {
  68. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Missing_$_inserted',
  69. formattedContent: () => (
  70. <>
  71. <p>
  72. You need to enclose all mathematical expressions and symbols with
  73. special markers. These special markers create a ‘math mode’.
  74. </p>
  75. <p>
  76. Use <code>$...$</code> for inline math mode, and <code>\[...\]</code>
  77. or one of the mathematical environments (e.g. equation) for display
  78. math mode.
  79. </p>
  80. <p>
  81. This applies to symbols such as subscripts ( <code>_</code> ),
  82. integrals ( <code>\int</code> ), Greek letters ( <code>\alpha</code>,{' '}
  83. <code>\beta</code>, <code>\delta</code> ) and modifiers{' '}
  84. <code>{'(\\vec{x}'}</code>, <code>{'\\tilde{x}'})</code>.
  85. </p>
  86. </>
  87. ),
  88. },
  89. hint_reference_undefined: {
  90. extraInfoURL:
  91. 'https://www.overleaf.com/learn/Errors/There_were_undefined_references',
  92. formattedContent: () => (
  93. <>
  94. You have referenced something which has not yet been labelled. If you
  95. have labelled it already, make sure that what is written inside \ref
  96. {'{...}'} is the same as what is written inside \label
  97. {'{...}'}.
  98. </>
  99. ),
  100. },
  101. hint_there_were_undefined_references: {
  102. extraInfoURL:
  103. 'https://www.overleaf.com/learn/Errors/There_were_undefined_references',
  104. formattedContent: () => (
  105. <>
  106. You have referenced something which has not yet been labelled. If you
  107. have labelled it already, make sure that what is written inside \ref
  108. {'{...}'} is the same as what is written inside \label
  109. {'{...}'}.
  110. </>
  111. ),
  112. },
  113. hint_citation_on_page_undefined_on_input_line: {
  114. extraInfoURL:
  115. 'https://www.overleaf.com/learn/Errors/Citation_XXX_on_page_XXX_undefined_on_input_line_XXX',
  116. formattedContent: () => (
  117. <>
  118. You have cited something which is not included in your bibliography.
  119. Make sure that the citation (\cite
  120. {'{...}'}) has a corresponding key in your bibliography, and that both
  121. are spelled the same way.
  122. </>
  123. ),
  124. },
  125. hint_label_multiply_defined_labels: {
  126. extraInfoURL:
  127. 'https://www.overleaf.com/learn/Errors/There_were_multiply-defined_labels',
  128. formattedContent: () => (
  129. <>
  130. You have used the same label more than once. Check that each \label
  131. {'{...}'} labels only one item.
  132. </>
  133. ),
  134. },
  135. hint_float_specifier_changed: {
  136. extraInfoURL:
  137. 'https://www.overleaf.com/learn/Errors/%60!h%27_float_specifier_changed_to_%60!ht%27',
  138. formattedContent: () => (
  139. <>
  140. The float specifier 'h' is too strict of a demand for LaTeX to place
  141. your float in a nice way here. Try relaxing it by using 'ht', or even
  142. 'htbp' if necessary. If you want to try keep the float here anyway,
  143. check out the{' '}
  144. <WikiLink url="https://www.overleaf.com/learn/Positioning_of_Figures">
  145. float package
  146. </WikiLink>
  147. .
  148. </>
  149. ),
  150. },
  151. hint_no_positions_in_optional_float_specifier: {
  152. extraInfoURL:
  153. 'https://www.overleaf.com/learn/Errors/No_positions_in_optional_float_specifier',
  154. formattedContent: () => (
  155. <>
  156. You have forgotten to include a float specifier, which tells LaTeX where
  157. to position your figure. To fix this, either insert a float specifier
  158. inside the square brackets (e.g. \begin
  159. {'{figure}'}
  160. [h]), or remove the square brackets (e.g. \begin
  161. {'{figure}'}
  162. ). Find out more about float specifiers{' '}
  163. <WikiLink url="https://www.overleaf.com/learn/Positioning_of_Figures">
  164. here
  165. </WikiLink>
  166. .
  167. </>
  168. ),
  169. },
  170. hint_undefined_control_sequence: {
  171. formattedContent: details => {
  172. if (details?.length) {
  173. const command = details[0]
  174. const suggestion = packageSuggestionsForCommands.get(command)
  175. if (suggestion) {
  176. return (
  177. <>
  178. <p>
  179. We think you’ve got a missing package! The{' '}
  180. <code>{command}</code> command won't work unless you include
  181. <code>{suggestion.command}</code> in your{' '}
  182. <WikiLink url="https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes#The_preamble_of_a_document">
  183. document preamble
  184. </WikiLink>
  185. .{' '}
  186. <WikiLink url="https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes#Finding_and_using_LaTeX_packages">
  187. Learn more about packages
  188. </WikiLink>
  189. .
  190. </p>
  191. </>
  192. )
  193. }
  194. }
  195. return (
  196. <>
  197. The compiler is having trouble understanding a command you have used.
  198. Check that the command is spelled correctly. If the command is part of
  199. a package, make sure you have included the package in your preamble
  200. using <code>\usepackage</code>
  201. {'{...}'}.
  202. <div className="log-entry-content-link">
  203. <a
  204. href="https://www.overleaf.com/learn/Errors/Undefined_control_sequence"
  205. target="_blank"
  206. rel="noopener"
  207. >
  208. Learn more
  209. </a>
  210. </div>
  211. </>
  212. )
  213. },
  214. },
  215. hint_undefined_environment: {
  216. formattedContent: details => {
  217. if (details?.length) {
  218. const environment = details[0]
  219. const suggestion = packageSuggestionsForEnvironments.get(environment)
  220. if (suggestion) {
  221. return (
  222. <>
  223. <p>
  224. We think you’ve got a missing package! The{' '}
  225. <code>{environment}</code> environment won't work unless you
  226. include <code>{suggestion.command}</code> in your{' '}
  227. <WikiLink url="https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes#The_preamble_of_a_document">
  228. document preamble
  229. </WikiLink>
  230. .{' '}
  231. <WikiLink url="https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes#Finding_and_using_LaTeX_packages">
  232. Learn more about packages
  233. </WikiLink>
  234. .
  235. </p>
  236. </>
  237. )
  238. }
  239. }
  240. return (
  241. <>
  242. You have created an environment (using \begin
  243. {'{…}'} and \end
  244. {'{…}'} commands) which is not recognized. Make sure you have included
  245. the required package for that environment in your preamble, and that
  246. the environment is spelled correctly.
  247. <div className="log-entry-content-link">
  248. <a
  249. href="https://www.overleaf.com/learn/Errors%2FLaTeX%20Error%3A%20Environment%20XXX%20undefined"
  250. target="_blank"
  251. rel="noopener"
  252. >
  253. Learn more
  254. </a>
  255. </div>
  256. </>
  257. )
  258. },
  259. },
  260. hint_file_not_found: {
  261. extraInfoURL:
  262. 'https://www.overleaf.com/learn/Errors/File_XXX_not_found_on_input_line_XXX',
  263. formattedContent: () => (
  264. <>
  265. The compiler cannot find the file you want to include. Make sure that
  266. you have{' '}
  267. <WikiLink url="https://www.overleaf.com/learn/how-to/Including_images_on_Overleaf">
  268. uploaded the file
  269. </WikiLink>{' '}
  270. and{' '}
  271. <WikiLink url="https://www.overleaf.com/learn/Errors/File_XXX_not_found_on_input_line_XXX.">
  272. specified the file location correctly
  273. </WikiLink>
  274. .
  275. </>
  276. ),
  277. },
  278. hint_unknown_graphics_extension: {
  279. extraInfoURL:
  280. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Unknown_graphics_extension:_.XXX',
  281. formattedContent: () => (
  282. <>
  283. The compiler does not recognise the file type of one of your images.
  284. Make sure you are using a{' '}
  285. <WikiLink url="https://www.overleaf.com/learn/Errors/LaTeX_Error:_Unknown_graphics_extension:_.gif.">
  286. supported image format
  287. </WikiLink>{' '}
  288. for your choice of compiler, and check that there are no periods (.) in
  289. the name of your image.
  290. </>
  291. ),
  292. },
  293. hint_unknown_float_option_h: {
  294. extraInfoURL:
  295. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Unknown_float_option_%60H%27',
  296. formattedContent: () => (
  297. <>
  298. The compiler isn't recognizing the float option 'H'. Include \usepackage
  299. {'{float}'} in your preamble to fix this.
  300. </>
  301. ),
  302. },
  303. hint_unknown_float_option_q: {
  304. extraInfoURL:
  305. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Unknown_float_option_%60q%27',
  306. formattedContent: () => (
  307. <>
  308. You have used a float specifier which the compiler does not understand.
  309. You can learn more about the different float options available for
  310. placing figures{' '}
  311. <WikiLink url="https://www.overleaf.com/learn/Positioning_of_Figures">
  312. here
  313. </WikiLink>{' '}
  314. .
  315. </>
  316. ),
  317. },
  318. hint_math_allowed_only_in_math_mode: {
  319. extraInfoURL:
  320. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_%5Cmathrm_allowed_only_in_math_mode',
  321. formattedContent: () => (
  322. <>
  323. You have used a font command which is only available in math mode. To
  324. use this command, you must be in maths mode (E.g. $ … $ or \begin
  325. {'{math}'} … \end
  326. {'{math}'}
  327. ). If you want to use it outside of math mode, use the text version
  328. instead: \textrm, \textit, etc.
  329. </>
  330. ),
  331. },
  332. hint_mismatched_environment: {
  333. formattedContent: () => (
  334. <>
  335. You have used \begin
  336. {'{...}'} without a corresponding \end
  337. {'{...}'}.
  338. </>
  339. ),
  340. },
  341. hint_mismatched_brackets: {
  342. formattedContent: () => (
  343. <>You have used an open bracket without a corresponding close bracket.</>
  344. ),
  345. },
  346. hint_can_be_used_only_in_preamble: {
  347. extraInfoURL:
  348. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Can_be_used_only_in_preamble',
  349. formattedContent: () => (
  350. <>
  351. You have used a command in the main body of your document which should
  352. be used in the preamble. Make sure that \documentclass[…]
  353. {'{…}'} and all \usepackage
  354. {'{…}'} commands are written before \begin
  355. {'{document}'}.
  356. </>
  357. ),
  358. },
  359. hint_missing_right_inserted: {
  360. extraInfoURL:
  361. 'https://www.overleaf.com/learn/Errors/Missing_%5Cright_insertede',
  362. formattedContent: () => (
  363. <>
  364. You have started an expression with a \left command, but have not
  365. included a corresponding \right command. Make sure that your \left and
  366. \right commands balance everywhere, or else try using \Biggl and \Biggr
  367. commands instead as shown{' '}
  368. <WikiLink url="https://www.overleaf.com/learn/Errors/Missing_%5Cright_inserted">
  369. here
  370. </WikiLink>
  371. .
  372. </>
  373. ),
  374. },
  375. hint_double_superscript: {
  376. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Double_superscript',
  377. formattedContent: () => (
  378. <>
  379. You have written a double superscript incorrectly as a^b^c, or else you
  380. have written a prime with a superscript. Remember to include {'{and}'}{' '}
  381. when using multiple superscripts. Try a^
  382. {'{b ^ c}'} instead.
  383. </>
  384. ),
  385. },
  386. hint_double_subscript: {
  387. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Double_subscript',
  388. formattedContent: () => (
  389. <>
  390. You have written a double subscript incorrectly as a_b_c. Remember to
  391. include {'{and}'} when using multiple subscripts. Try a_
  392. {'{b_c}'} instead.
  393. </>
  394. ),
  395. },
  396. hint_no_author_given: {
  397. extraInfoURL: 'https://www.overleaf.com/learn/Errors/No_%5Cauthor_given',
  398. formattedContent: () => (
  399. <>
  400. You have used the \maketitle command, but have not specified any
  401. \author. To fix this, include an author in your preamble using the
  402. \author
  403. {'{…}'} command.
  404. </>
  405. ),
  406. },
  407. hint_somethings_wrong_perhaps_a_missing_item: {
  408. extraInfoURL:
  409. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Something%27s_wrong--perhaps_a_missing_%5Citem',
  410. formattedContent: () => (
  411. <>
  412. There are no entries found in a list you have created. Make sure you
  413. label list entries using the \item command, and that you have not used a
  414. list inside a table.
  415. </>
  416. ),
  417. },
  418. hint_misplaced_noalign: {
  419. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Misplaced_%5Cnoalign',
  420. formattedContent: () => (
  421. <>
  422. You have used a \hline command in the wrong place, probably outside a
  423. table. If the \hline command is written inside a table, try including \\
  424. before it.
  425. </>
  426. ),
  427. },
  428. hint_no_line_here_to_end: {
  429. extraInfoURL:
  430. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_There%27s_no_line_here_to_end',
  431. formattedContent: () => (
  432. <>
  433. You have used a \\ or \newline command where LaTeX was not expecting
  434. one. Make sure that you only use line breaks after blocks of text, and
  435. be careful using linebreaks inside lists and other environments.
  436. </>
  437. ),
  438. },
  439. hint_verb_ended_by_end_of_line: {
  440. extraInfoURL:
  441. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_%5Cverb_ended_by_end_of_line',
  442. formattedContent: () => (
  443. <>
  444. You have used a \verb command incorrectly. Try replacling the \verb
  445. command with \begin
  446. {'{verbatim}'}
  447. …\end
  448. {'{verbatim}'}
  449. .\
  450. </>
  451. ),
  452. },
  453. hint_illegal_unit_of_measure_pt_inserted: {
  454. extraInfoURL:
  455. 'https://www.overleaf.com/learn/Errors%2FIllegal%20unit%20of%20measure%20(pt%20inserted)',
  456. formattedContent: () => (
  457. <>
  458. You have written a length, but have not specified the appropriate units
  459. (pt, mm, cm etc.). If you have not written a length, check that you have
  460. not witten a linebreak \\ followed by square brackets […] anywhere.
  461. </>
  462. ),
  463. },
  464. hint_extra_right: {
  465. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Extra_%5Cright',
  466. formattedContent: () => (
  467. <>
  468. You have written a \right command without a corresponding \left command.
  469. Check that all \left and \right commands balance everywhere.
  470. </>
  471. ),
  472. },
  473. hint_missing_begin_document_: {
  474. extraInfoURL:
  475. 'https://www.overleaf.com/learn/Errors%2FLaTeX%20Error%3A%20Missing%20%5Cbegin%20document',
  476. formattedContent: () => (
  477. <>
  478. No \begin
  479. {'{document}'} command was found. Make sure you have included \begin
  480. {'{document}'} in your preamble, and that your main document is set
  481. correctly.
  482. </>
  483. ),
  484. },
  485. hint_mismatched_environment2: {
  486. formattedContent: () => (
  487. <>
  488. You have used \begin
  489. {'{}'} without a corresponding \end
  490. {'{}'}.
  491. </>
  492. ),
  493. },
  494. hint_mismatched_environment3: {
  495. formattedContent: () => (
  496. <>
  497. You have used \begin
  498. {'{}'} without a corresponding \end
  499. {'{}'}.
  500. </>
  501. ),
  502. },
  503. hint_mismatched_environment4: {
  504. formattedContent: () => (
  505. <>
  506. You have used \begin
  507. {'{}'} without a corresponding \end
  508. {'{}'}.
  509. </>
  510. ),
  511. },
  512. }
  513. export const ruleIds = Object.keys(hints)
  514. if (!getMeta('ol-wikiEnabled')) {
  515. Object.keys(hints).forEach(ruleId => {
  516. hints[ruleId].extraInfoURL = null
  517. })
  518. }
  519. export default hints